invoices: fix flake in TestInvoiceExpiryWithRegistry

This commit is contained in:
yyforyongyu committed 2023-02-10 20:52:36 +08:00
1 parent 3d61d157c6
commit 4a7d3bc9c2
1 file changed
+20 -13
+20 -13
View File
@@ -1006,27 +1006,34 @@ func TestInvoiceExpiryWithRegistry(t *testing.T) {
// Fwd time 1 day. // Fwd time 1 day.
testClock.SetTime(testTime.Add(24 * time.Hour)) testClock.SetTime(testTime.Add(24 * time.Hour))
// Give some time to the watcher to cancel everything.
time.Sleep(500 * time.Millisecond)
if err := registry.Stop(); err != nil {
t.Fatalf("failed to stop invoice registry: %v", err)
}
// Create the expected cancellation set before the final check. // Create the expected cancellation set before the final check.
expectedCancellations = append( expectedCancellations = append(
expectedCancellations, invoicesThatWillCancel..., expectedCancellations, invoicesThatWillCancel...,
) )
// Retrospectively check that all invoices that were expected to be // canceled returns a bool to indicate whether all the invoices are
// canceled are indeed canceled. // canceled.
for i := range expectedCancellations { canceled := func() bool {
invoice, err := registry.LookupInvoice(expectedCancellations[i]) for i := range expectedCancellations {
if err != nil { invoice, err := registry.LookupInvoice(
t.Fatalf("cannot find invoice: %v", err) expectedCancellations[i],
)
require.NoError(t, err)
if invoice.State != invpkg.ContractCanceled {
return false
}
} }
require.Equal(t, invpkg.ContractCanceled, invoice.State) return true
} }
// Retrospectively check that all invoices that were expected to be
// canceled are indeed canceled.
require.Eventually(t, canceled, testTimeout, 10*time.Millisecond)
// Finally stop the registry.
require.NoError(t, registry.Stop(), "failed to stop invoice registry")
} }
// TestOldInvoiceRemovalOnStart tests that we'll attempt to remove old canceled // TestOldInvoiceRemovalOnStart tests that we'll attempt to remove old canceled