Skip to content

Commit

Permalink
Improved synchronization issues with unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Stoyan Zoubev <Stoyan.Zoubev@bosch.io>
  • Loading branch information
stoyan-zoubev committed Oct 20, 2023
1 parent 729628e commit c51f78b
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions updatem/orchestration/update_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit c51f78b

Please sign in to comment.