File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1325,8 +1325,8 @@ const subscribeChanSizeDefault = 1_000
13251325// Client.SubscribeConfig.
13261326type 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments