From 378446f88c95a831a50cacbe3e13f17f82ef4f57 Mon Sep 17 00:00:00 2001 From: Jess Yuen Date: Sun, 19 Jul 2020 19:35:21 -0600 Subject: [PATCH] Fix flaky unit test (#108) 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 --- internal/app/orchestrator/orchestrator_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/app/orchestrator/orchestrator_test.go b/internal/app/orchestrator/orchestrator_test.go index a89b952e..121879f0 100644 --- a/internal/app/orchestrator/orchestrator_test.go +++ b/internal/app/orchestrator/orchestrator_test.go @@ -156,8 +156,6 @@ 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() @@ -165,6 +163,9 @@ func TestGoldenPath(t *testing.T) { 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))