From 6959c6487437f383e8cad2552dd64176f60fb2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Wed, 23 Jan 2019 13:13:11 +0000 Subject: [PATCH] add unit test to verify AddAddr doesn't shorten TTL. --- test/addr_book_suite.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/addr_book_suite.go b/test/addr_book_suite.go index 7cb4cf8..cbea8b8 100644 --- a/test/addr_book_suite.go +++ b/test/addr_book_suite.go @@ -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)) + }) } }