Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Fix test when receiving duplicate messages from p2p.
Browse files Browse the repository at this point in the history
  • Loading branch information
cl9200 committed Jul 31, 2018
1 parent 4478960 commit 18a4b96
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions core/transaction_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

"time"

"bytes"

"github.com/medibloc/go-medibloc/core"
"github.com/medibloc/go-medibloc/util/byteutils"
"github.com/medibloc/go-medibloc/util/testutil"
Expand All @@ -35,21 +37,30 @@ func TestTransactionManager(t *testing.T) {
tx := testutil.NewRandomSignedTransaction(t)

mgrs[0].Broadcast(tx)
var actual *core.Transaction
for actual == nil {
actual = mgrs[1].Pop()
time.Sleep(time.Millisecond)

found := false
for i := 0; i < 100; i++ {
actual := mgrs[1].Pop()
if actual != nil && bytes.Equal(tx.Hash(), actual.Hash()) {
found = true
break
}
time.Sleep(10 * time.Millisecond)
}
assert.EqualValues(t, tx.Hash(), actual.Hash())
assert.True(t, found)

tx = testutil.NewRandomSignedTransaction(t)
mgrs[1].Relay(tx)
actual = nil
for actual == nil {
actual = mgrs[0].Pop()
time.Sleep(time.Millisecond)
found = false
for i := 0; i < 100; i++ {
actual := mgrs[0].Pop()
if actual != nil && bytes.Equal(tx.Hash(), actual.Hash()) {
found = true
break
}
time.Sleep(10 * time.Millisecond)
}
assert.EqualValues(t, tx.Hash(), actual.Hash())
assert.True(t, found)
}

func TestTransactionManagerAbnormalTx(t *testing.T) {
Expand Down

0 comments on commit 18a4b96

Please sign in to comment.