aboutsummaryrefslogtreecommitdiffstats
path: root/light
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2017-01-06 10:44:58 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2017-01-06 11:34:35 +0800
commit66979aa468b6329aabf49542bd3db14e59010c20 (patch)
tree80480c1abc825fffd7315e7e8e375f84d9faddce /light
parent93f9c023ccda2256079484d6c2a3159818ba6691 (diff)
downloaddexon-66979aa468b6329aabf49542bd3db14e59010c20.tar.gz
dexon-66979aa468b6329aabf49542bd3db14e59010c20.tar.zst
dexon-66979aa468b6329aabf49542bd3db14e59010c20.zip
light: fixed data race in TestTxPool
Diffstat (limited to 'light')
-rw-r--r--light/txpool_test.go35
1 files changed, 19 insertions, 16 deletions
diff --git a/light/txpool_test.go b/light/txpool_test.go
index 759b6b8ab..f3eb7980d 100644
--- a/light/txpool_test.go
+++ b/light/txpool_test.go
@@ -32,20 +32,22 @@ import (
)
type testTxRelay struct {
- send, nhMined, nhRollback, discard int
+ send, discard, mined chan int
}
func (self *testTxRelay) Send(txs types.Transactions) {
- self.send = len(txs)
+ self.send <- len(txs)
}
func (self *testTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash) {
- self.nhMined = len(mined)
- self.nhRollback = len(rollback)
+ m := len(mined)
+ if m != 0 {
+ self.mined <- m
+ }
}
func (self *testTxRelay) Discard(hashes []common.Hash) {
- self.discard = len(hashes)
+ self.discard <- len(hashes)
}
const poolTestTxs = 1000
@@ -94,7 +96,11 @@ func TestTxPool(t *testing.T) {
}
odr := &testOdr{sdb: sdb, ldb: ldb}
- relay := &testTxRelay{}
+ relay := &testTxRelay{
+ send: make(chan int, 1),
+ discard: make(chan int, 1),
+ mined: make(chan int, 1),
+ }
lightchain, _ := NewLightChain(odr, testChainConfig(), pow, evmux)
lightchain.SetValidator(bproc{})
txPermanent = 50
@@ -106,36 +112,33 @@ func TestTxPool(t *testing.T) {
s := sentTx(i - 1)
e := sentTx(i)
for i := s; i < e; i++ {
- relay.send = 0
pool.Add(ctx, testTx[i])
- got := relay.send
+ got := <-relay.send
exp := 1
if got != exp {
t.Errorf("relay.Send expected len = %d, got %d", exp, got)
}
}
- relay.nhMined = 0
- relay.nhRollback = 0
- relay.discard = 0
if _, err := lightchain.InsertHeaderChain([]*types.Header{block.Header()}, 1); err != nil {
panic(err)
}
- time.Sleep(time.Millisecond * 30)
- got := relay.nhMined
+ got := <-relay.mined
exp := minedTx(i) - minedTx(i-1)
if got != exp {
t.Errorf("relay.NewHead expected len(mined) = %d, got %d", exp, got)
}
- got = relay.discard
exp = 0
if i > int(txPermanent)+1 {
exp = minedTx(i-int(txPermanent)-1) - minedTx(i-int(txPermanent)-2)
}
- if got != exp {
- t.Errorf("relay.Discard expected len = %d, got %d", exp, got)
+ if exp != 0 {
+ got = <-relay.discard
+ if got != exp {
+ t.Errorf("relay.Discard expected len = %d, got %d", exp, got)
+ }
}
}
}