File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ func (b *AckBuffer) Ack(seq uint64) error {
137
137
indexAcked := seq - b .firstSeqNum
138
138
if indexAcked >= b .nextIndexToDeliver {
139
139
nextSeq := uint64 (0 )
140
- if b .buff [b .nextIndexToDeliver ] != nil {
140
+ if b .nextIndexToDeliver < uint64 ( len ( b . buff )) && b . buff [b .nextIndexToDeliver ] != nil {
141
141
nextSeq = b .buff [b .nextIndexToDeliver ].SeqNum
142
142
}
143
143
return fmt .Errorf ("acked message (seq: %d) has not yet been delivered (next: %d)" , seq , nextSeq )
Original file line number Diff line number Diff line change @@ -221,6 +221,38 @@ func TestAckBufferBoundaries(t *testing.T) {
221
221
if len (out ) != 10 {
222
222
t .Errorf ("unexpected number of unacked events: %+v" , out )
223
223
}
224
+
225
+ // Case 4: ack overflow
226
+ b , err = NewAckBuffer (AckBufferOptions {})
227
+ b .UpdateCapacity (3 )
228
+ if err != nil {
229
+ t .Errorf ("failed creating ack buffer: %v" , err )
230
+ return
231
+ }
232
+
233
+ if ! b .Add (& protocol.DataMessage {}, 0 ) {
234
+ t .Error ("failed to add" )
235
+ }
236
+ if ! b .Add (& protocol.DataMessage {}, 0 ) {
237
+ t .Error ("failed to add" )
238
+ }
239
+ if ! b .Add (& protocol.DataMessage {}, 0 ) {
240
+ t .Error ("failed to add" )
241
+ }
242
+
243
+ if b .GetNextToDeliver (0 ) == nil {
244
+ t .Error ("should have been able to get a delivery" )
245
+ }
246
+ if b .GetNextToDeliver (0 ) == nil {
247
+ t .Error ("should have been able to get a delivery" )
248
+ }
249
+ if b .GetNextToDeliver (0 ) == nil {
250
+ t .Error ("should have been able to get a delivery" )
251
+ }
252
+
253
+ if err := b .Ack (4 ); err == nil {
254
+ t .Errorf ("invalid ack should have generated an error" )
255
+ }
224
256
}
225
257
226
258
func TestAckAlways (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments