Skip to content

Commit a916a2e

Browse files
authored
Correct comment on SubscribeConfig.ChanSize + validation test cases (#1272)
1 parent a5db4c6 commit a916a2e

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,8 @@ const subscribeChanSizeDefault = 1_000
13251325
// Client.SubscribeConfig.
13261326
type SubscribeConfig struct {
13271327
// ChanSize is the size of the buffered channel that will be created for the
1328-
// subscription. Incoming events that overall this number because a listener
1329-
// isn't reading from the channel in a timely manner will be dropped.
1328+
// subscription. Incoming events that would overflow this buffer because a
1329+
// listener isn't reading from the channel in a timely manner will be dropped.
13301330
//
13311331
// Defaults to 1000.
13321332
ChanSize int

subscription_manager_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,31 @@ func Test_SubscriptionManager(t *testing.T) {
169169
require.Contains(t, strings.TrimSpace(logBuf.String()), "Subscription event dropped due to full buffer")
170170
require.Contains(t, logBuf.String(), "event_kind=queue_paused")
171171
})
172+
173+
t.Run("PanicOnNegativeChanSize", func(t *testing.T) {
174+
t.Parallel()
175+
176+
manager := newSubscriptionManager(riversharedtest.BaseServiceArchetype(t), nil)
177+
178+
require.PanicsWithValue(t, "SubscribeConfig.ChanSize must be greater or equal to 1", func() {
179+
_, _ = manager.SubscribeConfig(&SubscribeConfig{
180+
ChanSize: -1,
181+
Kinds: []EventKind{EventKindQueuePaused},
182+
})
183+
})
184+
})
185+
186+
t.Run("UsesDefaultChanSizeWhenZero", func(t *testing.T) {
187+
t.Parallel()
188+
189+
manager := newSubscriptionManager(riversharedtest.BaseServiceArchetype(t), nil)
190+
191+
sub, cancelSub := manager.SubscribeConfig(&SubscribeConfig{
192+
ChanSize: 0,
193+
Kinds: []EventKind{EventKindQueuePaused},
194+
})
195+
t.Cleanup(cancelSub)
196+
197+
require.Equal(t, subscribeChanSizeDefault, cap(sub))
198+
})
172199
}

0 commit comments

Comments
 (0)