Skip to content

Commit

Permalink
Merge pull request #52 from raulk/master
Browse files Browse the repository at this point in the history
Add unit test to verify AddAddr doesn't shorten TTL
  • Loading branch information
raulk authored Feb 5, 2019
2 parents bdd0cd6 + 0e9ce4e commit d3ce7dc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions p2p/host/peerstore/test/addr_book_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ func testAddAddress(ab pstore.AddrBook) func(*testing.T) {
time.Sleep(1200 * time.Millisecond)
testHas(t, addrs[2:], ab.Addrs(id))
})

t.Run("adding an existing address with an earlier expiration is noop", func(t *testing.T) {
id := generatePeerIds(1)[0]
addrs := generateAddrs(3)

ab.AddAddrs(id, addrs, time.Hour)

// same address as before but with a lower TTL
ab.AddAddrs(id, addrs[2:], time.Second)

// after the initial TTL has expired, check that all three addresses are still present (i.e. the TTL on
// the modified one was not shortened).
time.Sleep(2100 * time.Millisecond)
testHas(t, addrs, ab.Addrs(id))
})
}
}

Expand Down

0 comments on commit d3ce7dc

Please sign in to comment.