From 56e6119f782f1a99d56be9debf03c8e0b5de939a Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Mon, 1 Apr 2024 10:52:13 +0300 Subject: [PATCH] rpcsrv: fix TestSubClientWaitWithMissedEvent Add error channel to prevent data race in the test. Increase waiting interval for subscriptions awaiting up to 2 seconds. Failing is caused by slow subscriptions. Close #2958 Signed-off-by: Ekaterina Pavlova Signed-off-by: Ekaterina Pavlova --- pkg/services/rpcsrv/client_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index 487569b79..8f70762e3 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -2051,9 +2051,14 @@ func testSubClientWaitWithMissedEvent(t *testing.T, local bool) { tx := b1.Transactions[0] rcvr := make(chan *state.AppExecResult) + errCh := make(chan error) // Error channel for goroutine errors + go func() { aer, err := act.Wait(tx.Hash(), tx.ValidUntilBlock, nil) - require.NoError(t, err) + if err != nil { + errCh <- err + return + } rcvr <- aer }() @@ -2064,7 +2069,7 @@ func testSubClientWaitWithMissedEvent(t *testing.T, local bool) { rpcSrv.subsLock.Lock() defer rpcSrv.subsLock.Unlock() return len(rpcSrv.subscribers) == 1 - }, time.Second, 100*time.Millisecond) + }, 2*time.Second, 100*time.Millisecond) rpcSrv.subsLock.Lock() // Suppress normal event delivery. @@ -2101,6 +2106,8 @@ waitloop: require.Equal(t, trigger.Application, aer.Trigger) require.Equal(t, vmstate.Halt, aer.VMState) break waitloop + case err := <-errCh: + t.Fatalf("Error waiting for transaction: %v", err) case <-time.NewTimer(chain.GetConfig().TimePerBlock).C: t.Fatal("transaction failed to be awaited") }