diff --git a/tests/virtual-payment.go b/tests/virtual-payment.go index 93143c09..46acce6a 100644 --- a/tests/virtual-payment.go +++ b/tests/virtual-payment.go @@ -178,11 +178,21 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err // Run the job(s) utils.RunJobs(createVirtualPaymentsJob, runConfig.PaymentTestDuration, int64(runConfig.ConcurrentPaymentJobs)) - // Wait for 1/10 the payment time so any hubs can close their channels - // Even though our channels are closed, the hubs could be behind in processing messages. - time.Sleep(runConfig.PaymentTestDuration / 10) + + // We wait to allow hubs to finish processing messages and close out their channels. + // The duration we wait is based on the payment test duration and the amount of concurrent jobs. + toSleep := runConfig.PaymentTestDuration / 10 * time.Duration(runConfig.ConcurrentPaymentJobs) + // Restrict the sleep duration to be between 1 and 30 seconds + if toSleep > 30*time.Second { + toSleep = 30 * time.Second + } + if toSleep < 1*time.Second { + toSleep = 1 * time.Second + } + time.Sleep(toSleep) } client.MustSignalAndWait(ctx, "paymentsDone", runEnv.TestInstanceCount) + // TODO: Closing as a hub seems to fail: https://github.com/statechannels/go-nitro-testground/issues/134 // For now we avoid closing as a hub if len(ledgerIds) > 0 && me.Role != peer.Hub {