mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-30 06:31:20 +00:00
p2p/addrbook: add non-terminating test
This commit is contained in:
parent
8c88cc017a
commit
435eb6e2b3
@ -23,6 +23,40 @@ func createTempFileName(prefix string) string {
|
|||||||
return fname
|
return fname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddrBookPickAddress(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
fname := createTempFileName("addrbook_test")
|
||||||
|
|
||||||
|
// 0 addresses
|
||||||
|
book := NewAddrBook(fname, true)
|
||||||
|
book.SetLogger(log.TestingLogger())
|
||||||
|
assert.Zero(book.Size())
|
||||||
|
|
||||||
|
addr := book.PickAddress(50)
|
||||||
|
assert.Nil(addr, "expected no address")
|
||||||
|
|
||||||
|
randAddrs := randNetAddressPairs(t, 1)
|
||||||
|
addrSrc := randAddrs[0]
|
||||||
|
book.AddAddress(addrSrc.addr, addrSrc.src)
|
||||||
|
|
||||||
|
// pick an address when we only have new address
|
||||||
|
addr = book.PickAddress(0)
|
||||||
|
assert.NotNil(addr, "expected an address")
|
||||||
|
addr = book.PickAddress(50)
|
||||||
|
assert.NotNil(addr, "expected an address")
|
||||||
|
addr = book.PickAddress(100)
|
||||||
|
assert.NotNil(addr, "expected an address")
|
||||||
|
|
||||||
|
// pick an address when we only have old address
|
||||||
|
book.MarkGood(addrSrc.addr)
|
||||||
|
addr = book.PickAddress(0)
|
||||||
|
assert.NotNil(addr, "expected an address")
|
||||||
|
addr = book.PickAddress(50)
|
||||||
|
assert.NotNil(addr, "expected an address")
|
||||||
|
addr = book.PickAddress(100)
|
||||||
|
assert.NotNil(addr, "expected an address")
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddrBookSaveLoad(t *testing.T) {
|
func TestAddrBookSaveLoad(t *testing.T) {
|
||||||
fname := createTempFileName("addrbook_test")
|
fname := createTempFileName("addrbook_test")
|
||||||
|
|
||||||
@ -106,6 +140,10 @@ func TestAddrBookPromoteToOld(t *testing.T) {
|
|||||||
if len(selection) > book.Size() {
|
if len(selection) > book.Size() {
|
||||||
t.Errorf("selection could not be bigger than the book")
|
t.Errorf("selection could not be bigger than the book")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if book.Size() != 100 {
|
||||||
|
t.Errorf("Size is not 100. Got %v", book.Size())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddrBookHandlesDuplicates(t *testing.T) {
|
func TestAddrBookHandlesDuplicates(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user