Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Oct 22, 2024
1 parent f1b81d6 commit 7e318e9
Show file tree
Hide file tree
Showing 9 changed files with 7,668 additions and 14 deletions.
10 changes: 5 additions & 5 deletions mongo/integration/crud_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func TestClientBulkWrite(t *testing.T) {
})

mt.Run("bulkWrite handles individual WriteErrors across batches", func(mt *mtest.T) {
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, true)
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
err := coll.Drop(context.Background())
require.NoError(mt, err, "Drop error")
_, err = coll.InsertOne(context.Background(), bson.D{{"_id", 1}})
Expand Down Expand Up @@ -580,7 +580,7 @@ func TestClientBulkWrite(t *testing.T) {
})

mt.Run("bulkWrite handles a cursor requiring a getMore", func(mt *mtest.T) {
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, true)
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
err := coll.Drop(context.Background())
require.NoError(mt, err, "Drop error")

Expand Down Expand Up @@ -618,7 +618,7 @@ func TestClientBulkWrite(t *testing.T) {
})

mt.Run("bulkWrite handles a cursor requiring a getMore within a transaction", func(mt *mtest.T) {
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, true)
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
err := coll.Drop(context.Background())
require.NoError(mt, err, "Drop error")

Expand Down Expand Up @@ -693,7 +693,7 @@ func TestClientBulkWrite(t *testing.T) {
},
})

coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, true)
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
err = coll.Drop(context.Background())
require.NoError(mt, err, "Drop error")

Expand Down Expand Up @@ -910,7 +910,7 @@ func TestClientBulkWrite(t *testing.T) {

mt.ResetClient(options.Client().SetMonitor(monitor))

coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, true)
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
err = coll.Drop(context.Background())
require.NoError(mt, err, "Drop error")

Expand Down
53 changes: 53 additions & 0 deletions mongo/integration/csot_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.mongodb.org/mongo-driver/event"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/internal/integtest"
"go.mongodb.org/mongo-driver/internal/require"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down Expand Up @@ -160,4 +161,56 @@ func TestCSOTProse(t *testing.T) {
"expected ping to fail within 150ms")
})
})
mt.RunOpts("11. multi-batch bulkWrites", mtest.NewOptions().MinServerVersion("8.0").
AtlasDataLake(false).Topologies(mtest.Single), func(mt *mtest.T) {
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
err := coll.Drop(context.Background())
require.NoError(mt, err, "Drop error: %v", err)

mt.SetFailPoint(mtest.FailPoint{
ConfigureFailPoint: "failCommand",
Mode: mtest.FailPointMode{
Times: 2,
},
Data: mtest.FailPointData{
FailCommands: []string{"bulkWrite"},
BlockConnection: true,
BlockTimeMS: 1010,
},
})

var hello struct {
MaxBsonObjectSize int
MaxMessageSizeBytes int
}
err = mt.DB.RunCommand(context.Background(), bson.D{{"hello", 1}}).Decode(&hello)
require.NoError(mt, err, "Hello error: %v", err)

models := &mongo.ClientWriteModels{}
n := hello.MaxMessageSizeBytes/hello.MaxBsonObjectSize + 1
for i := 0; i < n; i++ {
models.
AppendInsertOne("db", "coll", &mongo.ClientInsertOneModel{
Document: bson.D{{"a", strings.Repeat("b", hello.MaxBsonObjectSize-500)}},
})
}

var cnt int
cm := &event.CommandMonitor{
Started: func(_ context.Context, evt *event.CommandStartedEvent) {
if evt.CommandName == "bulkWrite" {
cnt++
}
},
}
cliOptions := options.Client().
SetTimeout(2 * time.Second).
SetMonitor(cm).
ApplyURI(mtest.ClusterURI())
cli, err := mongo.Connect(context.Background(), cliOptions)
require.NoError(mt, err, "Connect error: %v", err)
_, err = cli.BulkWrite(context.Background(), models)
assert.ErrorContains(mt, err, "context deadline exceeded", "expected a timeout error, got: %v", err)
assert.Equal(mt, 2, cnt, "expected bulkWrite calls: %d, got: %d", 2, cnt)
})
}
22 changes: 13 additions & 9 deletions mongo/integration/unified/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import (
// expectedError represents an error that is expected to occur during a test. This type ignores the "isError" field in
// test files because it is always true if it is specified, so the runner can simply assert that an error occurred.
type expectedError struct {
IsClientError *bool `bson:"isClientError"`
IsTimeoutError *bool `bson:"isTimeoutError"`
ErrorSubstring *string `bson:"errorContains"`
Code *int32 `bson:"errorCode"`
CodeName *string `bson:"errorCodeName"`
IncludedLabels []string `bson:"errorLabelsContain"`
OmittedLabels []string `bson:"errorLabelsOmit"`
ExpectedResult *bson.RawValue `bson:"expectResult"`
ErrorResponse *bson.Raw `bson:"errorResponse"`
IsClientError *bool `bson:"isClientError"`
IsTimeoutError *bool `bson:"isTimeoutError"`
ErrorSubstring *string `bson:"errorContains"`
Code *int32 `bson:"errorCode"`
CodeName *string `bson:"errorCodeName"`
IncludedLabels []string `bson:"errorLabelsContain"`
OmittedLabels []string `bson:"errorLabelsOmit"`
ExpectedResult *bson.RawValue `bson:"expectResult"`
ErrorResponse *bson.Raw `bson:"errorResponse"`
WriteConcernErrors []bson.Raw `bson:"writeConcernErrors"`
}

// verifyOperationError compares the expected error to the actual operation result. If the expected parameter is nil,
Expand Down Expand Up @@ -140,6 +141,9 @@ func verifyOperationError(ctx context.Context, expected *expectedError, result *
return fmt.Errorf("error response comparison error: %w", err)
}
}
if expected.WriteConcernErrors != nil {
return fmt.Errorf("unspoorted field %v %v", result.Result.String(), result.Err)
}
return nil
}

Expand Down
220 changes: 220 additions & 0 deletions testdata/command-monitoring/unacknowledged-client-bulkWrite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
{
"description": "unacknowledged-client-bulkWrite",
"schemaVersion": "1.7",
"runOnRequirements": [
{
"minServerVersion": "8.0",
"serverless": "forbid"
}
],
"createEntities": [
{
"client": {
"id": "client",
"useMultipleMongoses": false,
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
"commandFailedEvent"
],
"uriOptions": {
"w": 0
}
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "command-monitoring-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "test"
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "command-monitoring-tests",
"documents": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
],
"_yamlAnchors": {
"namespace": "command-monitoring-tests.test"
},
"tests": [
{
"description": "A successful mixed client bulkWrite",
"operations": [
{
"object": "client",
"name": "clientBulkWrite",
"arguments": {
"models": [
{
"insertOne": {
"namespace": "command-monitoring-tests.test",
"document": {
"_id": 4,
"x": 44
}
}
},
{
"updateOne": {
"namespace": "command-monitoring-tests.test",
"filter": {
"_id": 3
},
"update": {
"$set": {
"x": 333
}
}
}
}
],
"ordered": false
},
"expectResult": {
"insertedCount": {
"$$unsetOrMatches": 0
},
"upsertedCount": {
"$$unsetOrMatches": 0
},
"matchedCount": {
"$$unsetOrMatches": 0
},
"modifiedCount": {
"$$unsetOrMatches": 0
},
"deletedCount": {
"$$unsetOrMatches": 0
},
"insertResults": {
"$$unsetOrMatches": {}
},
"updateResults": {
"$$unsetOrMatches": {}
},
"deleteResults": {
"$$unsetOrMatches": {}
}
}
},
{
"object": "collection",
"name": "find",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 333
},
{
"_id": 4,
"x": 44
}
]
}
],
"expectEvents": [
{
"client": "client",
"ignoreExtraEvents": true,
"events": [
{
"commandStartedEvent": {
"commandName": "bulkWrite",
"databaseName": "admin",
"command": {
"bulkWrite": 1,
"errorsOnly": true,
"ordered": false,
"ops": [
{
"insert": 0,
"document": {
"_id": 4,
"x": 44
}
},
{
"update": 0,
"filter": {
"_id": 3
},
"updateMods": {
"$set": {
"x": 333
}
},
"multi": false
}
],
"nsInfo": [
{
"ns": "command-monitoring-tests.test"
}
]
}
}
},
{
"commandSucceededEvent": {
"commandName": "bulkWrite",
"reply": {
"ok": 1,
"nInserted": {
"$$exists": false
},
"nMatched": {
"$$exists": false
},
"nModified": {
"$$exists": false
},
"nUpserted": {
"$$exists": false
},
"nDeleted": {
"$$exists": false
}
}
}
}
]
}
]
}
]
}
Loading

0 comments on commit 7e318e9

Please sign in to comment.