-
Notifications
You must be signed in to change notification settings - Fork 911
GODRIVER-1028 return correct error indexes for bulkWrite #483
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1067,6 +1067,77 @@ func TestCollection(t *testing.T) { | |
assert.Equal(mt, expectedModel, actualModel, "expected model %v in BulkWriteException, got %v", | ||
expectedModel, actualModel) | ||
}) | ||
mt.Run("unordered writeError index", func(mt *mtest.T) { | ||
cappedOpts := bson.D{{"capped", true}, {"size", 64 * 1024}} | ||
divjotarora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Use a capped collection to get WriteErrors for delete operations | ||
capped := mt.CreateCollection(mtest.Collection{ | ||
Name: "deleteOne_capped", | ||
CreateOpts: cappedOpts, | ||
}, true) | ||
models := []mongo.WriteModel{ | ||
mongo.NewInsertOneModel().SetDocument(bson.D{{"_id", "id1"}}), | ||
mongo.NewInsertOneModel().SetDocument(bson.D{{"_id", "id3"}}), | ||
} | ||
_, err := capped.BulkWrite(mtest.Background, models, options.BulkWrite()) | ||
assert.Nil(t, err, "BulkWrite error: %v", err) | ||
|
||
// UpdateOne and ReplaceOne models are batched together, so they each appear once | ||
models = []mongo.WriteModel{ | ||
divjotarora marked this conversation as resolved.
Show resolved
Hide resolved
divjotarora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", "id0"}}), | ||
mongo.NewDeleteManyModel().SetFilter(bson.D{{"_id", "id0"}}), | ||
kevinAlbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mongo.NewUpdateOneModel().SetFilter(bson.D{{"_id", "id3"}}).SetUpdate(bson.D{{"$set", bson.D{{"_id", 3.14159}}}}), | ||
mongo.NewInsertOneModel().SetDocument(bson.D{{"_id", "id1"}}), | ||
mongo.NewDeleteManyModel().SetFilter(bson.D{{"_id", "id0"}}), | ||
mongo.NewUpdateManyModel().SetFilter(bson.D{{"_id", "id3"}}).SetUpdate(bson.D{{"$set", bson.D{{"_id", 3.14159}}}}), | ||
mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", "id0"}}), | ||
mongo.NewInsertOneModel().SetDocument(bson.D{{"_id", "id1"}}), | ||
mongo.NewReplaceOneModel().SetFilter(bson.D{{"_id", "id3"}}).SetReplacement(bson.D{{"_id", 3.14159}}), | ||
mongo.NewUpdateManyModel().SetFilter(bson.D{{"_id", "id3"}}).SetUpdate(bson.D{{"$set", bson.D{{"_id", 3.14159}}}}), | ||
} | ||
_, err = capped.BulkWrite(mtest.Background, models, options.BulkWrite().SetOrdered(false)) | ||
bwException, ok := err.(mongo.BulkWriteException) | ||
assert.True(mt, ok, "expected error of type %T, got %T", mongo.BulkWriteException{}, err) | ||
|
||
assert.Equal(mt, len(bwException.WriteErrors), 10, "expected 10 writeErrors, got %v", len(bwException.WriteErrors)) | ||
for _, writeErr := range bwException.WriteErrors { | ||
switch writeErr.Request.(type) { | ||
case *mongo.DeleteOneModel: | ||
assert.True(mt, writeErr.Index == 0 || writeErr.Index == 6, | ||
"expected index 0 or 6, got %v", writeErr.Index) | ||
case *mongo.DeleteManyModel: | ||
assert.True(mt, writeErr.Index == 1 || writeErr.Index == 4, | ||
"expected index 1 or 4, got %v", writeErr.Index) | ||
case *mongo.UpdateManyModel: | ||
assert.True(mt, writeErr.Index == 5 || writeErr.Index == 9, | ||
"expected index 5 or 9, got %v", writeErr.Index) | ||
case *mongo.InsertOneModel: | ||
assert.True(mt, writeErr.Index == 3 || writeErr.Index == 7, | ||
"expected index 3 or 7, got %v", writeErr.Index) | ||
case *mongo.UpdateOneModel: | ||
assert.Equal(mt, writeErr.Index, 2, "expected index 2, got %v", writeErr.Index) | ||
case *mongo.ReplaceOneModel: | ||
assert.Equal(mt, writeErr.Index, 8, "expected index 8, got %v", writeErr.Index) | ||
} | ||
|
||
} | ||
}) | ||
mt.Run("unordered upsertID index", func(mt *mtest.T) { | ||
id1 := "id1" | ||
id3 := "id3" | ||
models := []mongo.WriteModel{ | ||
mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", "id0"}}), | ||
mongo.NewReplaceOneModel().SetFilter(bson.D{{"_id", id1}}).SetReplacement(bson.D{{"_id", id1}}).SetUpsert(true), | ||
mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", "id2"}}), | ||
mongo.NewReplaceOneModel().SetFilter(bson.D{{"_id", id3}}).SetReplacement(bson.D{{"_id", id3}}).SetUpsert(true), | ||
mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", "id4"}}), | ||
} | ||
res, err := mt.Coll.BulkWrite(mtest.Background, models, options.BulkWrite().SetOrdered(false)) | ||
assert.Nil(mt, err, "bulkwrite error: %v", err) | ||
|
||
assert.Equal(mt, len(res.UpsertedIDs), 2, "expected 2 UpsertedIDs, got %v", len(res.UpsertedIDs)) | ||
assert.Equal(mt, res.UpsertedIDs[1].(string), id1, "expected UpsertedIDs[1] to be %v, got %v", id1, res.UpsertedIDs[1]) | ||
assert.Equal(mt, res.UpsertedIDs[3].(string), id3, "expected UpsertedIDs[3] to be %v, got %v", id3, res.UpsertedIDs[3]) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also going to ask whether there are tests of individual commands being split into multiple batches. Though that was addressed in GODRIVER-1363 and appears to be tested in c814cfb#diff-1572fa8947f9463542abdc5cb3a11528R204. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that will be handled in GODRIVER-1715 |
||
unackClientOpts := options.Client(). | ||
SetWriteConcern(writeconcern.New(writeconcern.W(0))) | ||
unackMtOpts := mtest.NewOptions(). | ||
|
Uh oh!
There was an error while loading. Please reload this page.