Skip to content

Commit 2102fdb

Browse files
committed
tapgarden: use require.Eventually in assertPendingBatchExists
Refactor assertPendingBatchExists to use require.Eventually, allowing additional time for the state machine to reach the expected state. This improves test reliability by reducing flakiness and making the unit test more robust.
1 parent 56f9a5b commit 2102fdb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tapgarden/planter_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,15 @@ func (t *mintingTestHarness) queueSeedlingsInBatch(isFunded bool,
318318
func (t *mintingTestHarness) assertPendingBatchExists(numSeedlings int) {
319319
t.Helper()
320320

321-
batch, err := t.planter.PendingBatch()
322-
require.NoError(t, err)
323-
require.NotNil(t, batch)
324-
require.Len(t, batch.Seedlings, numSeedlings)
321+
// The planter is a state machine, so we need to wait until it has
322+
// reached the expected state.
323+
require.Eventually(t, func() bool {
324+
batch, err := t.planter.PendingBatch()
325+
require.NoError(t, err)
326+
327+
require.NotNil(t, batch)
328+
return len(batch.Seedlings) == numSeedlings
329+
}, defaultTimeout, wait.PollInterval)
325330
}
326331

327332
// assertNoActiveBatch asserts that no pending batch exists.

0 commit comments

Comments
 (0)