From 5eb88d13ceeb454bccfef2fc52f5ca966ee39770 Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky Date: Tue, 5 Nov 2024 12:06:21 -0600 Subject: [PATCH] Fix flaky TestLifecycleSCEPExpiration test. (#23534) #20936 # Checklist for submitter - [x] Added/updated tests --- .../service/integration_mdm_lifecycle_test.go | 7 ++++++- server/service/integration_mdm_test.go | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/service/integration_mdm_lifecycle_test.go b/server/service/integration_mdm_lifecycle_test.go index b9c648a0e3..4bbc784435 100644 --- a/server/service/integration_mdm_lifecycle_test.go +++ b/server/service/integration_mdm_lifecycle_test.go @@ -590,8 +590,13 @@ func (s *integrationMDMTestSuite) setupLifecycleSettings() { // Host is renewing SCEP certificates func (s *integrationMDMTestSuite) TestLifecycleSCEPCertExpiration() { t := s.T() - t.Skip("flaky test, see https://github.com/fleetdm/fleet/issues/20936") ctx := context.Background() + + // Skip worker jobs to avoid running into timing issues with this test. + // We can manually run the jobs if needed with s.runWorker(). + s.skipWorkerJobs = true + t.Cleanup(func() { s.skipWorkerJobs = false }) + // ensure there's a token for automatic enrollments s.enableABM(t.Name()) s.runDEPSchedule() diff --git a/server/service/integration_mdm_test.go b/server/service/integration_mdm_test.go index 3f1f782ac0..319d85ae0c 100644 --- a/server/service/integration_mdm_test.go +++ b/server/service/integration_mdm_test.go @@ -97,14 +97,16 @@ type integrationMDMTestSuite struct { onIntegrationsScheduleDone func() // function called when integrationsSchedule.Trigger() job completed mdmStorage *mysql.NanoMDMStorage worker *worker.Worker - mdmCommander *apple_mdm.MDMAppleCommander - logger kitlog.Logger - scepChallenge string - appleVPPConfigSrv *httptest.Server - appleVPPConfigSrvConfig *appleVPPConfigSrvConf - appleITunesSrv *httptest.Server - appleGDMFSrv *httptest.Server - mockedDownloadFleetdmMeta fleetdbase.Metadata + // Flag to skip jobs processing by worker + skipWorkerJobs bool + mdmCommander *apple_mdm.MDMAppleCommander + logger kitlog.Logger + scepChallenge string + appleVPPConfigSrv *httptest.Server + appleVPPConfigSrvConfig *appleVPPConfigSrvConf + appleITunesSrv *httptest.Server + appleGDMFSrv *httptest.Server + mockedDownloadFleetdmMeta fleetdbase.Metadata } // appleVPPConfigSrvConf is used to configure the mock server that mocks Apple's VPP endpoints. @@ -261,6 +263,9 @@ func (s *integrationMDMTestSuite) SetupSuite() { ctx, name, s.T().Name(), 1*time.Minute, ds, ds, schedule.WithLogger(logger), schedule.WithJob("integrations_worker", func(ctx context.Context) error { + if s.skipWorkerJobs { + return nil + } return s.worker.ProcessJobs(ctx) }), schedule.WithJob("dep_cooldowns", func(ctx context.Context) error {