From c51f78bfe43115a85bebdcefd3248212c1a841a0 Mon Sep 17 00:00:00 2001 From: Stoyan Zoubev Date: Fri, 20 Oct 2023 09:54:11 +0300 Subject: [PATCH] Improved synchronization issues with unit tests. Signed-off-by: Stoyan Zoubev --- updatem/orchestration/update_manager_test.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/updatem/orchestration/update_manager_test.go b/updatem/orchestration/update_manager_test.go index 63851bf..eefbb40 100644 --- a/updatem/orchestration/update_manager_test.go +++ b/updatem/orchestration/update_manager_test.go @@ -174,8 +174,11 @@ func TestApplyDesiredStateWhileInProgress(t *testing.T) { eventCallback.EXPECT().HandleCurrentStateEvent("device", test.ActivityID, testInventory) // start first Apply operation: it blocks until another Apply operation is rejected - wg.Add(1) - go updateManager.Apply(ctx, test.ActivityID, desiredState1) + wg.Add(2) + go func() { + updateManager.Apply(ctx, test.ActivityID, desiredState1) + wg.Done() + }() <-chanApplyStarted assert.True(t, updateManager.inProgress) assert.Equal(t, test.ActivityID, updateManager.activityInProgress) @@ -195,20 +198,11 @@ func TestApplyDesiredStateWhileInProgress(t *testing.T) { domainUpdateManager.EXPECT().Get(ctx, idAccepted).Return(nil, nil) mockUpdateOrchestrator.EXPECT().Apply(context.Background(), domainUpdateManagers, idAccepted, desiredState1, eventCallback).Times(1) eventCallback.EXPECT().HandleCurrentStateEvent("device", idAccepted, testInventory) - for checkIfInProgress(updateManager) { - time.Sleep(100 * time.Millisecond) - } updateManager.Apply(ctx, idAccepted, desiredState1) assert.False(t, updateManager.inProgress) assert.Equal(t, "", updateManager.activityInProgress) } -func checkIfInProgress(updateManager *aggregatedUpdateManager) bool { - updateManager.applyLock.Lock() - defer updateManager.applyLock.Unlock() - return updateManager.inProgress -} - func TestDisposeUpdateManager(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish()