From 2038a3369a25a82352c8b600d6cf1ccf58f08ed1 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 3 May 2023 12:03:03 -0500 Subject: [PATCH 1/4] bugfix: reduce flakiness in follower node test --- node/follower_node_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/node/follower_node_test.go b/node/follower_node_test.go index cbc77b3eb6..52389be39a 100644 --- a/node/follower_node_test.go +++ b/node/follower_node_test.go @@ -204,8 +204,20 @@ func TestSyncRoundWithRemake(t *testing.T) { } followNode, _ = remakeableFollowNode(t, tempDir, maxAcctLookback) - status, err := followNode.Status() - require.NoError(t, err) + + // wait for follower to catch up. This rarely is neeeded, but it can happen + // and cause flaky test failures. + // Timing out can still occur, but is less likely than the simply being + // behind a few rounds. + var status StatusReport + for stop := false; !stop; { + st, err := followNode.Status() + require.NoError(t, err) + if st.LastRound >= newRound { + stop = true + status = st + } + } require.Equal(t, newRound, status.LastRound) // syncRound should be at From db7416d75b3968a66aee2077a58e5c47ecaa3913 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 3 May 2023 12:11:29 -0500 Subject: [PATCH 2/4] Update node/follower_node_test.go --- node/follower_node_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/node/follower_node_test.go b/node/follower_node_test.go index 52389be39a..185c0582b9 100644 --- a/node/follower_node_test.go +++ b/node/follower_node_test.go @@ -205,10 +205,9 @@ func TestSyncRoundWithRemake(t *testing.T) { followNode, _ = remakeableFollowNode(t, tempDir, maxAcctLookback) - // wait for follower to catch up. This rarely is neeeded, but it can happen - // and cause flaky test failures. - // Timing out can still occur, but is less likely than the simply being - // behind a few rounds. + // Wait for follower to catch up. This rarely is needed, but can happen + // and cause flakey test failures. Timing out can still occur, but is less + // likely than the being caught behind a few rounds. var status StatusReport for stop := false; !stop; { st, err := followNode.Status() From a68d1f35e51aee69783c20c12add3655144bb97e Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 3 May 2023 13:25:36 -0500 Subject: [PATCH 3/4] sleep in between Status checks --- node/follower_node_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/node/follower_node_test.go b/node/follower_node_test.go index 185c0582b9..4a3c6f5c62 100644 --- a/node/follower_node_test.go +++ b/node/follower_node_test.go @@ -18,6 +18,7 @@ package node import ( "testing" + "time" "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" @@ -206,15 +207,17 @@ func TestSyncRoundWithRemake(t *testing.T) { followNode, _ = remakeableFollowNode(t, tempDir, maxAcctLookback) // Wait for follower to catch up. This rarely is needed, but can happen - // and cause flakey test failures. Timing out can still occur, but is less + // and cause flakey test failures. Timing out can still occur, but is less // likely than the being caught behind a few rounds. - var status StatusReport + var status *StatusReport for stop := false; !stop; { st, err := followNode.Status() require.NoError(t, err) if st.LastRound >= newRound { stop = true - status = st + status = &st + } else { + time.Sleep(500 * time.Millisecond) } } require.Equal(t, newRound, status.LastRound) From 7ab3bb833580c2f59ff5a72f745ee686da6edfd9 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Wed, 3 May 2023 15:27:45 -0500 Subject: [PATCH 4/4] require.Eventually instead of manual while-loop --- node/follower_node_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/node/follower_node_test.go b/node/follower_node_test.go index 4a3c6f5c62..1295eb0339 100644 --- a/node/follower_node_test.go +++ b/node/follower_node_test.go @@ -210,16 +210,16 @@ func TestSyncRoundWithRemake(t *testing.T) { // and cause flakey test failures. Timing out can still occur, but is less // likely than the being caught behind a few rounds. var status *StatusReport - for stop := false; !stop; { + require.Eventually(t, func() bool { st, err := followNode.Status() require.NoError(t, err) if st.LastRound >= newRound { - stop = true status = &st - } else { - time.Sleep(500 * time.Millisecond) + return true } - } + return false + }, 10*time.Second, 500*time.Millisecond, "failed to reach newRound within the allowed time") + require.Equal(t, newRound, status.LastRound) // syncRound should be at