mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 22:05:18 +00:00
clist: add a few basic clist tests (#6727)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPanicOnMaxLength(t *testing.T) {
|
||||
@@ -334,3 +335,50 @@ FOR_LOOP2:
|
||||
t.Fatalf("number of pushed items (%d) not equal to number of seen items (%d)", pushed, seen)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoved(t *testing.T) {
|
||||
l := New()
|
||||
el1 := l.PushBack(1)
|
||||
el2 := l.PushBack(2)
|
||||
l.Remove(el1)
|
||||
require.True(t, el1.Removed())
|
||||
require.False(t, el2.Removed())
|
||||
}
|
||||
|
||||
func TestNextWaitChan(t *testing.T) {
|
||||
l := New()
|
||||
el1 := l.PushBack(1)
|
||||
t.Run("tail element should not have a closed nextWaitChan", func(t *testing.T) {
|
||||
select {
|
||||
case <-el1.NextWaitChan():
|
||||
t.Fatal("nextWaitChan should not have been closed")
|
||||
default:
|
||||
}
|
||||
})
|
||||
|
||||
el2 := l.PushBack(2)
|
||||
t.Run("adding element should close tail nextWaitChan", func(t *testing.T) {
|
||||
select {
|
||||
case <-el1.NextWaitChan():
|
||||
require.NotNil(t, el1.Next())
|
||||
default:
|
||||
t.Fatal("nextWaitChan should have been closed")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-el2.NextWaitChan():
|
||||
t.Fatal("nextWaitChan should not have been closed")
|
||||
default:
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("removing element should close its nextWaitChan", func(t *testing.T) {
|
||||
l.Remove(el2)
|
||||
select {
|
||||
case <-el2.NextWaitChan():
|
||||
require.Nil(t, el2.Next())
|
||||
default:
|
||||
t.Fatal("nextWaitChan should have been closed")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user