Skip to content

Commit

Permalink
Make mock timing test less sensitive to env
Browse files Browse the repository at this point in the history
The test was failing in github actions.
This change moves a possible allocation in NewTimer() out of the window between the asyncCall starting and the timer elapsing. As the allocation would be before the timer is started this does not risk making the timer effectively 0ms.
  • Loading branch information
brackendawson committed Oct 29, 2021
1 parent ad092bc commit 8cd9017
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,15 @@ func Test_Mock_Called_blocks(t *testing.T) {

ch := make(chan Arguments)

timer := time.NewTimer(1 * time.Millisecond)
defer timer.Stop()

go asyncCall(&mockedService.Mock, ch)

select {
case <-ch:
t.Fatal("should have waited")
case <-time.After(1 * time.Millisecond):
case <-timer.C:
}

returnArguments := <-ch
Expand Down

0 comments on commit 8cd9017

Please sign in to comment.