wtclient: demo addr iterator panic

This commit adds a test that shows that it is possible to cause the
AddressIterator to panic if the `Next` method is ever called twice when
the iterator is at the end of its list without Reset first being called.
This commit is contained in:
Elle Mouton committed 2023-03-30 12:29:24 +02:00
1 parent de80fffa6c
commit 1047514515
1 file changed
+23
+23
View File
@@ -216,4 +216,27 @@ func TestAddrIterator(t *testing.T) {
iter.ReleaseLock(addr3)
require.False(t, iter.HasLocked())
})
t.Run("calling Next twice without Reset panics", func(t *testing.T) {
t.Parallel()
// This defer-function asserts that a panic does occur.
defer func() {
r := recover()
require.NotNilf(t, r, "the code did not panic")
}()
// Initialise the iterator with addr1.
iter, err := newAddressIterator(addr1)
require.NoError(t, err)
a1 := iter.Peek()
require.Equal(t, addr1, a1)
_, err = iter.Next()
require.ErrorIs(t, err, ErrAddressesExhausted)
_, err = iter.Next()
require.ErrorIs(t, err, ErrAddressesExhausted)
})
}