From 888e4a6a7f13d77abc19fffc01bc597ce6915c69 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Mon, 31 Mar 2025 10:21:25 -0400 Subject: [PATCH] Fix data race with push notification in test (#27682) Fix for https://github.com/fleetdm/fleet/actions/runs/14098566529/job/39490440108 --- server/service/integration_mdm_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/service/integration_mdm_test.go b/server/service/integration_mdm_test.go index 16e2fb1d94..c7e03558c5 100644 --- a/server/service/integration_mdm_test.go +++ b/server/service/integration_mdm_test.go @@ -15311,14 +15311,22 @@ func (s *integrationMDMTestSuite) TestRecreateDeletedIPhoneBYOD() { require.Len(t, listHostsRes.Hosts, 0) // run the reviver cron job, will send a push notification to the deleted host + oriPushFunc := s.pushProvider.PushFunc + t.Cleanup(func() { s.pushProvider.PushFunc = oriPushFunc }) + var recordedPushes []*mdm.Push + var pushMutex sync.Mutex s.pushProvider.PushFunc = func(ctx context.Context, pushes []*mdm.Push) (map[string]*push.Response, error) { + pushMutex.Lock() recordedPushes = pushes + pushMutex.Unlock() return mockSuccessfulPush(ctx, pushes) } err := apple_mdm.IOSiPadOSRevive(context.Background(), s.ds, s.mdmCommander, s.logger) require.NoError(t, err) + pushMutex.Lock() require.Len(t, recordedPushes, 1) + pushMutex.Unlock() // do an MDM sync (as the host would when triggered by the notification), // will re-create the host and move it to its enrollment team