diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-20 06:46:54 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-20 18:41:40 +0800 |
commit | 50661f0e683b4975894a0e8fe16024724adef72d (patch) | |
tree | 1a7769500acdd3d2b5815c472b7e6701e8ae2d8f /blockpool/errors_test.go | |
parent | 01ff0b3176e6d83dcc5e6716f04301de71e3fc9e (diff) | |
download | dexon-50661f0e683b4975894a0e8fe16024724adef72d.tar.gz dexon-50661f0e683b4975894a0e8fe16024724adef72d.tar.zst dexon-50661f0e683b4975894a0e8fe16024724adef72d.zip |
peer suspension to disallow reconnect after disconnect on fatal error for set period (PeerSuspensionInterval)
Diffstat (limited to 'blockpool/errors_test.go')
-rw-r--r-- | blockpool/errors_test.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/blockpool/errors_test.go b/blockpool/errors_test.go index 65a161233..5188930f0 100644 --- a/blockpool/errors_test.go +++ b/blockpool/errors_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ethereum/go-ethereum/blockpool/test" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/pow" ) @@ -45,7 +46,7 @@ func TestVerifyPoW(t *testing.T) { first := false blockPoolTester.blockPool.verifyPoW = func(b pow.Block) bool { bb, _ := b.(*types.Block) - indexes := blockPoolTester.hashPool.HashesToIndexes([][]byte{bb.Hash()}) + indexes := blockPoolTester.hashPool.HashesToIndexes([]common.Hash{bb.Hash()}) if indexes[0] == 2 && !first { first = true return false @@ -122,3 +123,33 @@ func TestErrInsufficientChainInfo(t *testing.T) { t.Errorf("expected %v error, got %v", ErrInsufficientChainInfo, peer1.peerErrors) } } + +func TestPeerSuspension(t *testing.T) { + test.LogInit() + _, blockPool, blockPoolTester := newTestBlockPool(t) + blockPool.Config.PeerSuspensionInterval = 100 * time.Millisecond + + blockPool.Start() + + peer1 := blockPoolTester.newPeer("peer1", 1, 3) + peer1.AddPeer() + blockPool.peers.peerError("peer1", 0, "") + bestpeer, _ := blockPool.peers.getPeer("peer1") + if bestpeer != nil { + t.Errorf("peer1 not removed on error") + } + peer1.AddPeer() + bestpeer, _ = blockPool.peers.getPeer("peer1") + if bestpeer != nil { + t.Errorf("peer1 not removed on reconnect") + } + time.Sleep(100 * time.Millisecond) + peer1.AddPeer() + bestpeer, _ = blockPool.peers.getPeer("peer1") + if bestpeer == nil { + t.Errorf("peer1 not connected after PeerSuspensionInterval") + } + // blockPool.Wait(waitTimeout) + blockPool.Stop() + +} |