From dacf50038db6925439137d272b4a0235c826d4f7 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 22 Apr 2021 14:29:20 -0400 Subject: [PATCH] submatview: fix two flaky tests These tests can flake when we get a notification for an earlier event. Retry the read from update channel a few times to make sure we get the event we expect. --- agent/submatview/store_test.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/agent/submatview/store_test.go b/agent/submatview/store_test.go index 8a7bfafcdc..4f1e4d11a0 100644 --- a/agent/submatview/store_test.go +++ b/agent/submatview/store_test.go @@ -33,9 +33,13 @@ func TestStore_Get(t *testing.T) { newEventServiceHealthRegister(22, 2, "srv1")) runStep(t, "from empty store, starts materializer", func(t *testing.T) { - result, err := store.Get(ctx, req) - require.NoError(t, err) - require.Equal(t, uint64(22), result.Index) + var result Result + retry.Run(t, func(r *retry.R) { + var err error + result, err = store.Get(ctx, req) + require.NoError(r, err) + require.Equal(r, uint64(22), result.Index) + }) r, ok := result.Value.(fakeResult) require.True(t, ok) @@ -240,15 +244,17 @@ func TestStore_Notify(t *testing.T) { }) runStep(t, "updates are received", func(t *testing.T) { - select { - case update := <-ch: - require.NoError(t, update.Err) - require.Equal(t, cID, update.CorrelationID) - require.Equal(t, uint64(22), update.Meta.Index) - require.Equal(t, uint64(22), update.Result.(fakeResult).index) - case <-time.After(100 * time.Millisecond): - t.Fatalf("expected Get to unblock when new events are received") - } + retry.Run(t, func(r *retry.R) { + select { + case update := <-ch: + require.NoError(r, update.Err) + require.Equal(r, cID, update.CorrelationID) + require.Equal(r, uint64(22), update.Meta.Index) + require.Equal(r, uint64(22), update.Result.(fakeResult).index) + case <-time.After(100 * time.Millisecond): + r.Stop(fmt.Errorf("expected Get to unblock when new events are received")) + } + }) req.client.QueueEvents(newEventServiceHealthRegister(24, 2, "srv1"))