Skip to content

Commit 89487ff

Browse files
committed
fix atomic batch publish test
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
1 parent 0693565 commit 89487ff

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

jetstreamext/errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const (
2222
JSErrCodeFastBatchInvalidPattern jetstream.ErrorCode = 10204
2323
JSErrCodeFastBatchInvalidID jetstream.ErrorCode = 10205
2424
JSErrCodeFastBatchUnknownID jetstream.ErrorCode = 10206
25+
26+
// Too many inflight error codes
27+
JSErrCodeAtomicPublishTooManyInflight jetstream.ErrorCode = 10210
28+
JSErrCodeBatchPublishTooManyInflight jetstream.ErrorCode = 10211
2529
)
2630

2731
var (
@@ -51,6 +55,12 @@ var (
5155
// ErrBatchPublishInvalidGapMode is returned when invalid batch gap mode is specified.
5256
ErrBatchPublishInvalidGapMode jetstream.JetStreamError = &jsError{apiErr: &jetstream.APIError{ErrorCode: JSErrCodeBatchPublishInvalidGapMode, Description: "invalid batch gap mode", Code: 400}}
5357

58+
// ErrAtomicPublishTooManyInflight is returned when there are too many inflight atomic publish batches.
59+
ErrAtomicPublishTooManyInflight jetstream.JetStreamError = &jsError{apiErr: &jetstream.APIError{ErrorCode: JSErrCodeAtomicPublishTooManyInflight, Description: "atomic publish too many inflight", Code: 429}}
60+
61+
// ErrBatchPublishTooManyInflight is returned when there are too many inflight batch publish batches.
62+
ErrBatchPublishTooManyInflight jetstream.JetStreamError = &jsError{apiErr: &jetstream.APIError{ErrorCode: JSErrCodeBatchPublishTooManyInflight, Description: "batch publish too many inflight", Code: 429}}
63+
5464
// ErrBatchClosed is returned when attempting to use a batch that has been closed.
5565
ErrBatchClosed = &jsError{message: "batch publisher closed"}
5666

jetstreamext/test/publishbatch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,16 @@ func TestBatchPublisher(t *testing.T) {
310310
err = batch.Add("test.1", []byte("message 1"))
311311
if err != nil {
312312
// With flow control enabled (WaitFirst=true by default), the first Add may fail
313-
if errors.Is(err, jetstreamext.ErrBatchPublishIncomplete) {
313+
if errors.Is(err, jetstreamext.ErrBatchPublishIncomplete) || errors.Is(err, jetstreamext.ErrAtomicPublishTooManyInflight) || errors.Is(err, jetstreamext.ErrBatchPublishTooManyInflight) {
314314
// This is expected - too many outstanding batches
315315
return
316316
}
317317
t.Fatalf("Unexpected error adding message to batch: %v", err)
318318
}
319319
// If Add didn't fail, Commit should fail
320320
_, err = batch.Commit(ctx, "test.2", []byte("message 2"))
321-
if !errors.Is(err, jetstreamext.ErrBatchPublishIncomplete) {
322-
t.Fatalf("Expected ErrBatchPublishIncomplete when too many outstanding batches, got %v", err)
321+
if !errors.Is(err, jetstreamext.ErrBatchPublishIncomplete) && !errors.Is(err, jetstreamext.ErrAtomicPublishTooManyInflight) && !errors.Is(err, jetstreamext.ErrBatchPublishTooManyInflight) {
322+
t.Fatalf("Expected too many inflight error when too many outstanding batches, got %v", err)
323323
}
324324
})
325325

0 commit comments

Comments
 (0)