Skip to content

Commit

Permalink
Fix rare concurrency bug in test code
Browse files Browse the repository at this point in the history
In the test "RPS Adapts in Response to Throttling", the assert part
of the unit test becomes unblocked after `doneStopping()` unblocks,
which happens after the second `StopQueryWithContext` calls IS ABOUT
TO return.

Usually the test was working correctly where the stopper code for
the second `StopQueryWithContext` call would fully execute. However,
very occasionally, the assertions start running before all the stopper
code runs, resulting in `stopAdapter.AssertExpectations(t)` failing
at line 2215.

This commit fixes that.
  • Loading branch information
vcschapp committed Jan 30, 2023
1 parent 09dcc02 commit 30ce985
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2186,11 +2186,11 @@ func TestQueryManager_Query(t *testing.T) {
stopAdapter.
On("increase").
Return(true).
Once()
Maybe() // Increase RPS after second StopQuery. (May happen after test ends.)
stopAdapter.
On("value").
Return(99_999.5).
Once() // Calculate minDelay after RPS increase.
Maybe() // Calculate minDelay after RPS increase. (May happen after test ends.)
stopAdapter.
On("value").
Return(99_999.5).
Expand Down

0 comments on commit 30ce985

Please sign in to comment.