Skip to content

Commit 6d5c28d

Browse files
committed
tapgraden: log full expected and actual seedlings to debug test flake
This test has been flaking frequently in CI. Previously, it only logged the expected and actual counts of seedlings (e.g., "expected 5 seedlings, got 4"). Now, it outputs the full expected and actual seedling values to provide more context and help diagnose the issue.
1 parent 33dd9a5 commit 6d5c28d

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

tapgarden/planter_test.go

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,15 @@ func (t *mintingTestHarness) queueSeedlingsInBatch(isFunded bool,
331331

332332
// assertPendingBatchExists asserts that a pending batch is found and it has
333333
// numSeedlings assets registered.
334-
func (t *mintingTestHarness) assertPendingBatchExists(numSeedlings int) {
335-
t.Helper()
334+
func (t *mintingTestHarness) assertPendingBatchExists(
335+
expectedSeedlings []*tapgarden.Seedling) {
336336

337337
// The planter is a state machine, so we need to wait until it has
338338
// reached the expected state.
339+
var (
340+
numExpectedSeedlings = len(expectedSeedlings)
341+
lastActualSeedlings map[string]*tapgarden.Seedling
342+
)
339343
err := wait.NoError(func() error {
340344
batch, err := t.planter.PendingBatch()
341345
if err != nil {
@@ -348,14 +352,43 @@ func (t *mintingTestHarness) assertPendingBatchExists(numSeedlings int) {
348352
"non-nil")
349353
}
350354

351-
if len(batch.Seedlings) < numSeedlings {
355+
lastActualSeedlings = batch.Seedlings
356+
357+
if len(batch.Seedlings) < numExpectedSeedlings {
352358
return fmt.Errorf("expected %d seedlings, got %d",
353-
numSeedlings, len(batch.Seedlings))
359+
numExpectedSeedlings, len(batch.Seedlings))
354360
}
355361

356362
return nil
357363
}, defaultTimeout)
358-
require.NoError(t, err)
364+
if err != nil {
365+
// Report any missing seedlings.
366+
spewCfg := spew.ConfigState{
367+
// Disable .String() and other methods.
368+
DisableMethods: true,
369+
Indent: " ",
370+
}
371+
372+
for idx := range expectedSeedlings {
373+
expectedSeedling := expectedSeedlings[idx]
374+
if lastActualSeedlings == nil {
375+
t.Logf("Missing expected seedling: %s",
376+
spewCfg.Sdump(expectedSeedling))
377+
continue
378+
}
379+
380+
_, ok := lastActualSeedlings[expectedSeedling.AssetName]
381+
if !ok {
382+
t.Logf("Missing expected seedling: %s",
383+
spewCfg.Sdump(expectedSeedling))
384+
}
385+
}
386+
387+
t.Fatalf("Batch seedling mismatch: \nactual seedlings: %s\n"+
388+
"expected seedlings: %s\nerror: %v",
389+
spew.Sdump(lastActualSeedlings),
390+
spew.Sdump(expectedSeedlings), err)
391+
}
359392
}
360393

361394
// assertNoActiveBatch asserts that no pending batch exists.
@@ -1089,7 +1122,7 @@ func (t *mintingTestHarness) queueInitialBatch(
10891122

10901123
// At this point, there should be a single pending batch with 5
10911124
// seedlings. The batch stored in the log should also match up exactly.
1092-
t.assertPendingBatchExists(numSeedlings)
1125+
t.assertPendingBatchExists(seedlings)
10931126

10941127
// Before we tick the batch, we record all existing batches, so we can
10951128
// make sure a new one was created.
@@ -1329,7 +1362,7 @@ func testMintingCancelFinalize(t *mintingTestHarness) {
13291362
}
13301363
t.queueSeedlingsInBatch(false, seedlings...)
13311364

1332-
t.assertPendingBatchExists(numSeedlings)
1365+
t.assertPendingBatchExists(seedlings)
13331366
t.assertSeedlingsExist(seedlings, nil)
13341367

13351368
// If we attempt to queue a seedling with the same name as a pending
@@ -1781,7 +1814,7 @@ func testFundSealBeforeFinalize(t *mintingTestHarness) {
17811814
// Add the seedlings modified earlier to the batch, and check that they
17821815
// were added correctly.
17831816
t.queueSeedlingsInBatch(true, seedlings...)
1784-
t.assertPendingBatchExists(numSeedlings)
1817+
t.assertPendingBatchExists(seedlings)
17851818
t.assertSeedlingsExist(seedlings, nil)
17861819

17871820
verboseBatches, err := t.planter.ListBatches(

0 commit comments

Comments
 (0)