Skip to content

Commit 2e1ecc0

Browse files
authored
les, miner, accounts/abi/bind: fix load-sensitive unit tests (#20698)
1 parent 6df973d commit 2e1ecc0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

accounts/abi/bind/bind_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ var bindTests = []struct {
13841384
if n != 3 {
13851385
t.Fatalf("Invalid bar0 event")
13861386
}
1387-
case <-time.NewTimer(100 * time.Millisecond).C:
1387+
case <-time.NewTimer(3 * time.Second).C:
13881388
t.Fatalf("Wait bar0 event timeout")
13891389
}
13901390
@@ -1395,7 +1395,7 @@ var bindTests = []struct {
13951395
if n != 1 {
13961396
t.Fatalf("Invalid bar event")
13971397
}
1398-
case <-time.NewTimer(100 * time.Millisecond).C:
1398+
case <-time.NewTimer(3 * time.Second).C:
13991399
t.Fatalf("Wait bar event timeout")
14001400
}
14011401
close(stopCh)

les/clientpool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func TestNodeDBExpiration(t *testing.T) {
517517
for _, c := range cases {
518518
ndb.setNB(c.ip, c.balance)
519519
}
520-
time.Sleep(100 * time.Millisecond) // Ensure the db expirer is registered.
520+
clock.WaitForTimers(1)
521521
clock.Run(time.Hour + time.Minute)
522522
select {
523523
case <-done:
@@ -527,7 +527,7 @@ func TestNodeDBExpiration(t *testing.T) {
527527
if iterated != 4 {
528528
t.Fatalf("Failed to evict useless negative balances, want %v, got %d", 4, iterated)
529529
}
530-
530+
clock.WaitForTimers(1)
531531
for _, c := range cases {
532532
ndb.setNB(c.ip, c.balance)
533533
}

miner/worker_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,16 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) {
215215
chain, _ := core.NewBlockChain(db2, nil, b.chain.Config(), engine, vm.Config{}, nil)
216216
defer chain.Stop()
217217

218-
loopErr := make(chan error)
219-
newBlock := make(chan struct{})
218+
var (
219+
loopErr = make(chan error)
220+
newBlock = make(chan struct{})
221+
subscribe = make(chan struct{})
222+
)
220223
listenNewBlock := func() {
221224
sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
222225
defer sub.Unsubscribe()
223226

227+
subscribe <- struct{}{}
224228
for item := range sub.Chan() {
225229
block := item.Data.(core.NewMinedBlockEvent).Block
226230
_, err := chain.InsertChain([]*types.Block{block})
@@ -234,9 +238,11 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) {
234238
w.skipSealHook = func(task *task) bool {
235239
return len(task.receipts) == 0
236240
}
237-
w.start() // Start mining!
238241
go listenNewBlock()
239242

243+
<-subscribe // Ensure the subscription is created
244+
w.start() // Start mining!
245+
240246
for i := 0; i < 5; i++ {
241247
b.txPool.AddLocal(b.newRandomTx(true))
242248
b.txPool.AddLocal(b.newRandomTx(false))

0 commit comments

Comments
 (0)