Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky unit tests fix #48

Merged
merged 10 commits into from
Dec 13, 2023
6 changes: 4 additions & 2 deletions blockchain/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -178,7 +178,9 @@ func TestSubscription_NilEventAfterClosingSubscription(t *testing.T) {
evt := sub.GetEvent()
if evt != nil {
receivedEvtCount++
} else {
}

if expectedBlockCount <= receivedEvtCount {
return
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/block_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/throttling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestThrottling(t *testing.T) {
}

go func() {
time.Sleep(time.Millisecond * 150)
time.Sleep(time.Millisecond * 50)

defer wg.Done()

Expand Down
8 changes: 0 additions & 8 deletions network/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -764,8 +762,6 @@ func TestSubscribe(t *testing.T) {
}

t.Run("should call callback", func(t *testing.T) {
t.Parallel()

server := setupServer(t, true)

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -784,8 +780,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)

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -803,8 +797,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)

ctx, cancel := context.WithCancel(context.Background())
Expand Down
1 change: 1 addition & 0 deletions syncer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions txpool/event_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -141,10 +141,10 @@ func TestEventSubscription_ProcessedEvents(t *testing.T) {
}

wg.Wait()
eventWaitCtx, eventWaitFn := context.WithTimeout(context.Background(), 10*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)
return nil, atomic.LoadInt64(&processed) != int64(testCase.expectedProcessed)
}); err != nil {
t.Fatalf("Unable to wait for events to be processed, %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down