diff options
author | hozan23 <hozan23@karyontech.net> | 2024-06-13 06:02:24 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-06-13 06:02:24 +0200 |
commit | 8c2d37e093ca64d591fc0aec15a7e2ed424b2e47 (patch) | |
tree | fd9bc62e29087a18e7eb4bdd0a1f587ba63e5dd5 /client/channels_test.go | |
parent | a338905a7f8a2206161cc15f07bda872b9bfc09c (diff) |
use message dispatcher to process responses and notifications & spread out comments
Diffstat (limited to 'client/channels_test.go')
-rw-r--r-- | client/channels_test.go | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/client/channels_test.go b/client/channels_test.go deleted file mode 100644 index 4465fed..0000000 --- a/client/channels_test.go +++ /dev/null @@ -1,110 +0,0 @@ -package client - -import ( - "sync" - "sync/atomic" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestNotifyChannel(t *testing.T) { - - chans := newChannels[int, int](10) - - chanKey := 1 - rx := chans.add(chanKey) - - chanKey2 := 2 - rx2 := chans.add(chanKey2) - - var wg sync.WaitGroup - - wg.Add(1) - go func() { - for i := 0; i < 50; i++ { - err := chans.notify(chanKey, i) - assert.Nil(t, err) - } - - // drop the channel - tx := chans.remove(chanKey) - close(tx) - wg.Done() - }() - - wg.Add(1) - go func() { - for i := 0; i < 50; i++ { - err := chans.notify(chanKey2, i) - assert.Nil(t, err) - } - - // drop the channel - tx := chans.remove(chanKey2) - close(tx) - wg.Done() - }() - - var receivedItem atomic.Int32 - - wg.Add(1) - go func() { - for range rx { - receivedItem.Add(1) - } - wg.Done() - }() - - wg.Add(1) - go func() { - for range rx2 { - receivedItem.Add(1) - } - wg.Done() - }() - - wg.Wait() - assert.Equal(t, receivedItem.Load(), int32(100)) -} - -func TestRemoveChannel(t *testing.T) { - - chans := newChannels[int, int](1) - - chanKey := 1 - rx := chans.add(chanKey) - - tx := chans.remove(chanKey) - assert.Equal(t, chans.length(), 0, "channels should be empty") - - tx <- 3 - val := <-rx - assert.Equal(t, val, 3) - - tx = chans.remove(chanKey) - assert.Nil(t, tx) - - err := chans.notify(chanKey, 1) - assert.NotNil(t, err) -} - -func TestClearChannels(t *testing.T) { - - chans := newChannels[int, int](1) - - chanKey := 1 - rx := chans.add(chanKey) - - chans.clear() - assert.Equal(t, chans.length(), 0, "channels should be empty") - - _, ok := <-rx - assert.False(t, ok, "chan closed") - - tx := chans.remove(chanKey) - assert.Nil(t, tx) - - err := chans.notify(chanKey, 1) - assert.NotNil(t, err) -} |