Skip to content

Commit

Permalink
Fix flaky unit test (#108)
Browse files Browse the repository at this point in the history
Assert stats only after watches have been cleaned up. This prevents a
flaky case where we check that the stat has been incremented before it
the codepath is executed.

Signed-off-by: Jess Yuen <[email protected]>
  • Loading branch information
jessicayuen authored Jul 20, 2020
1 parent 2bc8500 commit 378446f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/app/orchestrator/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ func TestGoldenPath(t *testing.T) {

gotResponse := <-respChannel
assertEqualResponse(t, gotResponse, resp, req)
testutils.AssertCounterValue(t, mockScope.Snapshot().Counters(),
fmt.Sprintf("mock_orchestrator.%s.watch.fanout", aggregatedKey), 1)

ctx, cancel := context.WithCancel(context.Background())
cancel()
orchestrator.shutdown(ctx)
testutils.AssertSyncMapLen(t, 0, orchestrator.upstreamResponseMap.internal)

cancelWatch()

testutils.AssertCounterValue(t, mockScope.Snapshot().Counters(),
fmt.Sprintf("mock_orchestrator.%s.watch.fanout", aggregatedKey), 1)
testutils.AssertCounterValue(t, mockScope.Snapshot().Counters(),
fmt.Sprintf("mock_orchestrator.%s.watch.canceled", aggregatedKey), 1)
assert.Equal(t, 0, len(orchestrator.downstreamResponseMap.responseChannels))
Expand Down

0 comments on commit 378446f

Please sign in to comment.