major refactor to accommodate feed
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package gubgub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -10,26 +9,8 @@ import (
|
||||
func BenchmarkAsyncTopic_Publish(b *testing.B) {
|
||||
for _, tc := range publishCases {
|
||||
b.Run(tc.Name, func(b *testing.B) {
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
subscribersReady := make(chan struct{}, 1)
|
||||
defer close(subscribersReady)
|
||||
|
||||
topicClosed := make(chan struct{}, 1)
|
||||
defer close(topicClosed)
|
||||
|
||||
topic := NewAsyncTopic[int](ctx,
|
||||
WithOnSubscribe(func(count int) {
|
||||
if count == tc.Count {
|
||||
subscribersReady <- struct{}{}
|
||||
}
|
||||
}),
|
||||
WithOnClose(func() {
|
||||
topicClosed <- struct{}{}
|
||||
}),
|
||||
)
|
||||
onSubscribe, subscribersReady := withNotifyOnNthSubscriber(b, int64(tc.Count))
|
||||
topic := newTestAsyncTopic[int](b, onSubscribe)
|
||||
|
||||
for range tc.Count {
|
||||
require.NoError(b, topic.Subscribe(tc.Subscriber))
|
||||
@@ -45,10 +26,7 @@ func BenchmarkAsyncTopic_Publish(b *testing.B) {
|
||||
|
||||
b.StopTimer()
|
||||
|
||||
cancel()
|
||||
|
||||
// This just helps leaving as few running Go routines as possible when the next round starts
|
||||
<-topicClosed
|
||||
topic.Close()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user