From 21309ccb7beca995bcb44a2816a9ec4085385637 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Mon, 19 Jul 2021 10:02:21 -0400 Subject: [PATCH] clist: add a few basic clist tests (#6727) --- internal/libs/clist/clist_test.go | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/internal/libs/clist/clist_test.go b/internal/libs/clist/clist_test.go index 4b222e3d5..0c0a7a86e 100644 --- a/internal/libs/clist/clist_test.go +++ b/internal/libs/clist/clist_test.go @@ -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") + } + }) +}