From 970adb0745c760bc0bab98bfa1a75ded6080aacc Mon Sep 17 00:00:00 2001 From: Dusan Date: Sat, 9 Dec 2023 13:54:42 +0100 Subject: [PATCH 1/9] fix for flaky UT --- consensus/polybft/block_builder_test.go | 2 +- txpool/event_subscription_test.go | 2 +- txpool/txpool_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/polybft/block_builder_test.go b/consensus/polybft/block_builder_test.go index 6476bab278..9c0bdef87b 100644 --- a/consensus/polybft/block_builder_test.go +++ b/consensus/polybft/block_builder_test.go @@ -113,7 +113,7 @@ func TestBlockBuilder_BuildBlockTxOneFailedTxAndOneTakesTooMuchGas(t *testing.T) } bb := NewBlockBuilder(&BlockBuilderParams{ - BlockTime: time.Millisecond * 100, + BlockTime: time.Millisecond * 200, Parent: parentHeader, Coinbase: types.ZeroAddress, Executor: executor, diff --git a/txpool/event_subscription_test.go b/txpool/event_subscription_test.go index 5b0a0f9f0e..0ccafe92c2 100644 --- a/txpool/event_subscription_test.go +++ b/txpool/event_subscription_test.go @@ -141,7 +141,7 @@ func TestEventSubscription_ProcessedEvents(t *testing.T) { } wg.Wait() - eventWaitCtx, eventWaitFn := context.WithTimeout(context.Background(), 10*time.Second) + eventWaitCtx, eventWaitFn := context.WithTimeout(context.Background(), 20*time.Second) defer eventWaitFn() if _, err := tests.RetryUntilTimeout(eventWaitCtx, func() (interface{}, bool) { return nil, atomic.LoadInt64(&processed) < int64(testCase.expectedProcessed) diff --git a/txpool/txpool_test.go b/txpool/txpool_test.go index db3a576cbd..9d52c56156 100644 --- a/txpool/txpool_test.go +++ b/txpool/txpool_test.go @@ -3451,7 +3451,7 @@ func TestBatchTx_SingleAccount(t *testing.T) { for { select { case ev = <-subscription.subscriptionChannel: - case <-time.After(time.Second * 3): + case <-time.After(time.Second * 10): t.Fatal(fmt.Sprintf("timeout. processed: %d/%d and %d/%d. Added: %d", enqueuedCount, defaultMaxAccountEnqueued, promotedCount, defaultMaxAccountEnqueued, atomic.LoadUint64(&counter))) From 9bcedad892cb6f958d65385d129262bed8c758eb Mon Sep 17 00:00:00 2001 From: Dusan Date: Sat, 9 Dec 2023 14:24:44 +0100 Subject: [PATCH 2/9] timer different value --- txpool/event_subscription_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/txpool/event_subscription_test.go b/txpool/event_subscription_test.go index 0ccafe92c2..24e8a73aa5 100644 --- a/txpool/event_subscription_test.go +++ b/txpool/event_subscription_test.go @@ -141,7 +141,7 @@ func TestEventSubscription_ProcessedEvents(t *testing.T) { } wg.Wait() - eventWaitCtx, eventWaitFn := context.WithTimeout(context.Background(), 20*time.Second) + eventWaitCtx, eventWaitFn := context.WithTimeout(context.Background(), 30*time.Second) defer eventWaitFn() if _, err := tests.RetryUntilTimeout(eventWaitCtx, func() (interface{}, bool) { return nil, atomic.LoadInt64(&processed) < int64(testCase.expectedProcessed) From eb221587120430fa96e40829761d9e063e06cf20 Mon Sep 17 00:00:00 2001 From: Dusan Date: Sun, 10 Dec 2023 16:26:40 +0100 Subject: [PATCH 3/9] Small fixes for TestEventSubscription_ProcessedEvents --- txpool/event_subscription_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/txpool/event_subscription_test.go b/txpool/event_subscription_test.go index 24e8a73aa5..e7c6412927 100644 --- a/txpool/event_subscription_test.go +++ b/txpool/event_subscription_test.go @@ -117,7 +117,7 @@ func TestEventSubscription_ProcessedEvents(t *testing.T) { eventStore: &eventQueue{ events: make([]*proto.TxPoolEvent, 0), }, - notifyCh: make(chan struct{}), + notifyCh: make(chan struct{}, 10), } go subscription.runLoop() @@ -144,7 +144,7 @@ func TestEventSubscription_ProcessedEvents(t *testing.T) { eventWaitCtx, eventWaitFn := context.WithTimeout(context.Background(), 30*time.Second) defer eventWaitFn() if _, err := tests.RetryUntilTimeout(eventWaitCtx, func() (interface{}, bool) { - return nil, atomic.LoadInt64(&processed) < int64(testCase.expectedProcessed) + return nil, atomic.LoadInt64(&processed) != int64(testCase.expectedProcessed) }); err != nil { t.Fatalf("Unable to wait for events to be processed, %v", err) } From df1ea031db68da70b2de9158ae1bc12b6cb83500 Mon Sep 17 00:00:00 2001 From: Dusan Date: Mon, 11 Dec 2023 08:41:21 +0100 Subject: [PATCH 4/9] fix for TestSubscription_NilEventAfterClosingSubscription --- blockchain/subscription_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/blockchain/subscription_test.go b/blockchain/subscription_test.go index dc32740423..3abcbea705 100644 --- a/blockchain/subscription_test.go +++ b/blockchain/subscription_test.go @@ -168,7 +168,7 @@ func TestSubscription_NilEventAfterClosingSubscription(t *testing.T) { receivedEvtCount := 0 - worker := func(sub *subscription, expectedBlockCount uint8) { + worker := func(sub *subscription, expectedBlockCount int) { defer wg.Done() startTime := time.Now().UTC() @@ -178,7 +178,8 @@ func TestSubscription_NilEventAfterClosingSubscription(t *testing.T) { evt := sub.GetEvent() if evt != nil { receivedEvtCount++ - } else { + } + if expectedBlockCount <= receivedEvtCount { return } From 83269fa660936adf0569f991885d7d7d9a74b45e Mon Sep 17 00:00:00 2001 From: Dusan Date: Mon, 11 Dec 2023 12:09:16 +0100 Subject: [PATCH 5/9] some more fixes --- blockchain/subscription_test.go | 1 + jsonrpc/throttling_test.go | 2 +- syncer/client_test.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/blockchain/subscription_test.go b/blockchain/subscription_test.go index 3abcbea705..64803d2e2b 100644 --- a/blockchain/subscription_test.go +++ b/blockchain/subscription_test.go @@ -179,6 +179,7 @@ func TestSubscription_NilEventAfterClosingSubscription(t *testing.T) { if evt != nil { receivedEvtCount++ } + if expectedBlockCount <= receivedEvtCount { return } diff --git a/jsonrpc/throttling_test.go b/jsonrpc/throttling_test.go index 13b73ac905..5e8ea65235 100644 --- a/jsonrpc/throttling_test.go +++ b/jsonrpc/throttling_test.go @@ -48,7 +48,7 @@ func TestThrottling(t *testing.T) { } go func() { - time.Sleep(time.Millisecond * 150) + time.Sleep(time.Millisecond * 300) defer wg.Done() diff --git a/syncer/client_test.go b/syncer/client_test.go index 37b91eced1..061817ae55 100644 --- a/syncer/client_test.go +++ b/syncer/client_test.go @@ -211,6 +211,7 @@ func TestStatusPubSub(t *testing.T) { assert.NoError(t, err) + time.Sleep(3 * time.Second) // close channel and wait for events close(client.closeCh) From c4c8fd48ca9dddc2f602463860d82532612b28d2 Mon Sep 17 00:00:00 2001 From: Dusan Date: Mon, 11 Dec 2023 14:17:56 +0100 Subject: [PATCH 6/9] added require error in TestSubscribe --- network/server_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/network/server_test.go b/network/server_test.go index 74b29e4f75..ac6105d160 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -18,6 +18,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestConnLimit_Inbound(t *testing.T) { @@ -795,6 +796,8 @@ func TestSubscribe(t *testing.T) { // cancel before emitting cancel() + require.Error(t, ctx.Err()) + server.EmitEvent(event) _, received := waitForEvent(t, eventCh, time.Second*5) From a724b51ab6108d007a99753d1e7af9ee5a53ef54 Mon Sep 17 00:00:00 2001 From: Dusan Date: Mon, 11 Dec 2023 14:44:52 +0100 Subject: [PATCH 7/9] interval change rhrottling --- jsonrpc/throttling_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonrpc/throttling_test.go b/jsonrpc/throttling_test.go index 5e8ea65235..3686756030 100644 --- a/jsonrpc/throttling_test.go +++ b/jsonrpc/throttling_test.go @@ -48,7 +48,7 @@ func TestThrottling(t *testing.T) { } go func() { - time.Sleep(time.Millisecond * 300) + time.Sleep(time.Millisecond * 50) defer wg.Done() From d0899baadf3ea6005db3608324a861e70c960041 Mon Sep 17 00:00:00 2001 From: Dusan Date: Tue, 12 Dec 2023 12:24:24 +0100 Subject: [PATCH 8/9] removed parallel --- network/server_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/network/server_test.go b/network/server_test.go index ac6105d160..b3197fce32 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -18,7 +18,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestConnLimit_Inbound(t *testing.T) { @@ -765,7 +764,6 @@ func TestSubscribe(t *testing.T) { } t.Run("should call callback", func(t *testing.T) { - t.Parallel() server := setupServer(t, true) @@ -785,7 +783,6 @@ func TestSubscribe(t *testing.T) { }) t.Run("should not call callback after context is closed", func(t *testing.T) { - t.Parallel() server := setupServer(t, true) @@ -796,8 +793,6 @@ func TestSubscribe(t *testing.T) { // cancel before emitting cancel() - require.Error(t, ctx.Err()) - server.EmitEvent(event) _, received := waitForEvent(t, eventCh, time.Second*5) @@ -806,7 +801,6 @@ func TestSubscribe(t *testing.T) { }) t.Run("should not call callback after server closed", func(t *testing.T) { - t.Parallel() server := setupServer(t, false) From 0bd4c52e2ee642b83d5dc9dcc50a68cd645e7adb Mon Sep 17 00:00:00 2001 From: Dusan Date: Tue, 12 Dec 2023 12:46:55 +0100 Subject: [PATCH 9/9] fixes --- network/server_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/network/server_test.go b/network/server_test.go index b3197fce32..ff29676255 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -697,8 +697,6 @@ func TestRunDial(t *testing.T) { } func TestSubscribe(t *testing.T) { - t.Parallel() - setupServer := func(t *testing.T, shouldCloseAfterTest bool) *Server { t.Helper() @@ -764,7 +762,6 @@ func TestSubscribe(t *testing.T) { } t.Run("should call callback", func(t *testing.T) { - server := setupServer(t, true) ctx, cancel := context.WithCancel(context.Background()) @@ -783,7 +780,6 @@ func TestSubscribe(t *testing.T) { }) t.Run("should not call callback after context is closed", func(t *testing.T) { - server := setupServer(t, true) ctx, cancel := context.WithCancel(context.Background()) @@ -801,7 +797,6 @@ func TestSubscribe(t *testing.T) { }) t.Run("should not call callback after server closed", func(t *testing.T) { - server := setupServer(t, false) ctx, cancel := context.WithCancel(context.Background())