add ci conf and subscribe hook for the AsyncTopic

This commit is contained in:
2024-08-06 16:35:38 +01:00
parent d10ec9b0a7
commit ba97fcd89d
4 changed files with 55 additions and 5 deletions

View File

@@ -107,6 +107,34 @@ func TestAsyncTopic_WithOnClose(t *testing.T) {
}
}
func TestAsyncTopic_WithOnSubscribe(t *testing.T) {
const totalSub = 10
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
feedback := make(chan int, totalSub)
defer close(feedback)
topic := NewAsyncTopic[int](ctx, WithOnSubscribe(func(count int) { feedback <- count }))
for range totalSub {
topic.Subscribe(func(i int) bool { return true })
}
count := 0
for count < totalSub {
select {
case c := <-feedback:
count++
assert.Equal(t, count, c, "expected %d but got %d instead", count, c)
case <-time.After(time.Second):
t.Fatalf("expected %d feedback items by now but only got %d", totalSub, count)
}
}
}
func TestAsyncTopic_SubscribeClosedTopicError(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()