From c8a692046f4b09aca6ed6c7d6337d1c2c582f6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 23 Jan 2023 12:02:42 +0100 Subject: [PATCH] fix: itests: Fix flaky paych test --- itests/paych_api_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/itests/paych_api_test.go b/itests/paych_api_test.go index 353e22294..ea7e73dbc 100644 --- a/itests/paych_api_test.go +++ b/itests/paych_api_test.go @@ -38,7 +38,7 @@ func TestPaymentChannelsAPI(t *testing.T) { kit.QuietMiningLogs() ctx := context.Background() - blockTime := 5 * time.Millisecond + blockTime := 10 * time.Millisecond var ( paymentCreator kit.TestFullNode @@ -55,6 +55,15 @@ func TestPaymentChannelsAPI(t *testing.T) { bms := ens.BeginMiningMustPost(blockTime) bm := bms[0] + waitRecvInSync := func() { + // paymentCreator is the block miner, in some cases paymentReceiver may fall behind, so we wait for it to catch up + + head, err := paymentReceiver.ChainHead(ctx) + require.NoError(t, err) + + paymentReceiver.WaitTillChain(ctx, kit.HeightAtLeast(head.Height())) + } + // send some funds to register the receiver receiverAddr, err := paymentReceiver.WalletNew(ctx, types.KTSecp256k1) require.NoError(t, err) @@ -74,6 +83,8 @@ func TestPaymentChannelsAPI(t *testing.T) { channel, err := paymentCreator.PaychGetWaitReady(ctx, channelInfo.WaitSentinel) require.NoError(t, err) + waitRecvInSync() + // allocate three lanes var lanes []uint64 for i := 0; i < 3; i++ { @@ -110,6 +121,8 @@ func TestPaymentChannelsAPI(t *testing.T) { res := waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second*10, "settle") require.EqualValues(t, 0, res.Receipt.ExitCode, "Unable to settle payment channel") + waitRecvInSync() + creatorStore := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(paymentCreator))) // wait for the receiver to submit their vouchers