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:
1 file changed
+23
@@ -216,4 +216,27 @@ func TestAddrIterator(t *testing.T) {
|
|||||||
iter.ReleaseLock(addr3)
|
iter.ReleaseLock(addr3)
|
||||||
require.False(t, iter.HasLocked())
|
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user