Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in TestCollection/insert_many when nothing is inserted. #1991

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthewdale
Copy link
Collaborator

Summary

Only assert on the contents of InsertedIDs in the TestCollection/insert_many/return_only_inserted_ids test if the length is greater than 0.

Background & Motivation

The test TestCollection/insert_many/return_only_inserted_ids sometimes panics when the InsertMany fails. One of the assertions accesses the first ID in the InsertedIDs list, which panics if the list is empty. The panic hides the root cause error because the error assertions are later in the test code.

@matthewdale matthewdale force-pushed the fix-test-coll-panic branch from c1d1208 to 9c1a3fe Compare March 20, 2025 03:30
@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Mar 20, 2025
Copy link
Contributor

API Change Report

No changes found!

@matthewdale matthewdale requested review from qingyang-hu and removed request for prestonvasquez March 24, 2025 17:12
we, ok := err.(mongo.BulkWriteException)
assert.True(mt, ok, "expected error type %T, got %T", mongo.BulkWriteException{}, err)
numErrors := len(we.WriteErrors)
assert.Equal(mt, tc.numErrors, numErrors, "expected %v write errors, got %v", tc.numErrors, numErrors)
gotCode := we.WriteErrors[0].Code
assert.Equal(mt, errorDuplicateKey, gotCode, "expected error code %v, got %v", errorDuplicateKey, gotCode)

if len(res.InsertedIDs) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use a require.Greater()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants