Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/mongo/driver/batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *Batches) AppendBatchSequence(dst []byte, maxCount, totalSize int) (int,
idx, dst = bsoncore.ReserveLength(dst)
dst = append(dst, b.Identifier...)
dst = append(dst, 0x00)
var size int
size := len(dst)
var n int
for i := b.offset; i < len(b.Documents); i++ {
if n == maxCount {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (b *Batches) AppendBatchArray(dst []byte, maxCount, totalSize int) (int, []
}
l := len(dst)
aidx, dst := bsoncore.AppendArrayElementStart(dst, b.Identifier)
var size int
size := len(dst)
var n int
for i := b.offset; i < len(b.Documents); i++ {
if n == maxCount {
Expand Down
6 changes: 4 additions & 2 deletions x/mongo/driver/batches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func TestAppendBatchSequence(t *testing.T) {
batches := newTestBatches(t)

got := []byte{42}
totalMsgSize := len(batches.Documents[0]) + len(batches.Documents[1])
var n int
var err error
n, got, err = batches.AppendBatchSequence(got, 2, len(batches.Documents[0]))
n, got, err = batches.AppendBatchSequence(got, 2, totalMsgSize)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalMsgSize is not actually the total message size here (it excludes OP_MSG/section overhead and also includes the size of a document that isn’t expected to be appended). This makes the test’s intent fragile and tied to the current overhead/identifier length. Consider computing the size limit from the expected encoded bytes (e.g., build dst first and use len(dst) +/- 1) and/or rename the variable to reflect that it’s a size limit rather than an actual message size.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

@koenno koenno Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed the variable

assert.NoError(t, err)
assert.Equal(t, 1, n)

Expand All @@ -57,9 +58,10 @@ func TestAppendBatchArray(t *testing.T) {
batches := newTestBatches(t)

got := []byte{42}
totalMsgSize := len(batches.Documents[0]) + len(batches.Documents[1])
var n int
var err error
n, got, err = batches.AppendBatchArray(got, 2, len(batches.Documents[0]))
n, got, err = batches.AppendBatchArray(got, 2, totalMsgSize)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: the totalMsgSize value here isn’t the actual message size limit (it omits BSON array element overhead) and includes bytes for an element that shouldn’t be appended. To keep the test aligned with the totalSize contract, consider deriving the limit from the expected encoded dst length (or renaming the variable to indicate it’s a limit).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

@koenno koenno Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed the variable

assert.NoError(t, err)
assert.Equal(t, 1, n)

Expand Down
Loading