Skip to content

Commit 7e318e9

Browse files
committed
cleanup
1 parent f1b81d6 commit 7e318e9

File tree

9 files changed

+7668
-14
lines changed

9 files changed

+7668
-14
lines changed

mongo/integration/crud_prose_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func TestClientBulkWrite(t *testing.T) {
529529
})
530530

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

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

@@ -618,7 +618,7 @@ func TestClientBulkWrite(t *testing.T) {
618618
})
619619

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

@@ -693,7 +693,7 @@ func TestClientBulkWrite(t *testing.T) {
693693
},
694694
})
695695

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

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

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

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

mongo/integration/csot_prose_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"go.mongodb.org/mongo-driver/event"
1717
"go.mongodb.org/mongo-driver/internal/assert"
1818
"go.mongodb.org/mongo-driver/internal/integtest"
19+
"go.mongodb.org/mongo-driver/internal/require"
1920
"go.mongodb.org/mongo-driver/mongo"
2021
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
2122
"go.mongodb.org/mongo-driver/mongo/options"
@@ -160,4 +161,56 @@ func TestCSOTProse(t *testing.T) {
160161
"expected ping to fail within 150ms")
161162
})
162163
})
164+
mt.RunOpts("11. multi-batch bulkWrites", mtest.NewOptions().MinServerVersion("8.0").
165+
AtlasDataLake(false).Topologies(mtest.Single), func(mt *mtest.T) {
166+
coll := mt.CreateCollection(mtest.Collection{DB: "db", Name: "coll"}, false)
167+
err := coll.Drop(context.Background())
168+
require.NoError(mt, err, "Drop error: %v", err)
169+
170+
mt.SetFailPoint(mtest.FailPoint{
171+
ConfigureFailPoint: "failCommand",
172+
Mode: mtest.FailPointMode{
173+
Times: 2,
174+
},
175+
Data: mtest.FailPointData{
176+
FailCommands: []string{"bulkWrite"},
177+
BlockConnection: true,
178+
BlockTimeMS: 1010,
179+
},
180+
})
181+
182+
var hello struct {
183+
MaxBsonObjectSize int
184+
MaxMessageSizeBytes int
185+
}
186+
err = mt.DB.RunCommand(context.Background(), bson.D{{"hello", 1}}).Decode(&hello)
187+
require.NoError(mt, err, "Hello error: %v", err)
188+
189+
models := &mongo.ClientWriteModels{}
190+
n := hello.MaxMessageSizeBytes/hello.MaxBsonObjectSize + 1
191+
for i := 0; i < n; i++ {
192+
models.
193+
AppendInsertOne("db", "coll", &mongo.ClientInsertOneModel{
194+
Document: bson.D{{"a", strings.Repeat("b", hello.MaxBsonObjectSize-500)}},
195+
})
196+
}
197+
198+
var cnt int
199+
cm := &event.CommandMonitor{
200+
Started: func(_ context.Context, evt *event.CommandStartedEvent) {
201+
if evt.CommandName == "bulkWrite" {
202+
cnt++
203+
}
204+
},
205+
}
206+
cliOptions := options.Client().
207+
SetTimeout(2 * time.Second).
208+
SetMonitor(cm).
209+
ApplyURI(mtest.ClusterURI())
210+
cli, err := mongo.Connect(context.Background(), cliOptions)
211+
require.NoError(mt, err, "Connect error: %v", err)
212+
_, err = cli.BulkWrite(context.Background(), models)
213+
assert.ErrorContains(mt, err, "context deadline exceeded", "expected a timeout error, got: %v", err)
214+
assert.Equal(mt, 2, cnt, "expected bulkWrite calls: %d, got: %d", 2, cnt)
215+
})
163216
}

mongo/integration/unified/error.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import (
1919
// expectedError represents an error that is expected to occur during a test. This type ignores the "isError" field in
2020
// test files because it is always true if it is specified, so the runner can simply assert that an error occurred.
2121
type expectedError struct {
22-
IsClientError *bool `bson:"isClientError"`
23-
IsTimeoutError *bool `bson:"isTimeoutError"`
24-
ErrorSubstring *string `bson:"errorContains"`
25-
Code *int32 `bson:"errorCode"`
26-
CodeName *string `bson:"errorCodeName"`
27-
IncludedLabels []string `bson:"errorLabelsContain"`
28-
OmittedLabels []string `bson:"errorLabelsOmit"`
29-
ExpectedResult *bson.RawValue `bson:"expectResult"`
30-
ErrorResponse *bson.Raw `bson:"errorResponse"`
22+
IsClientError *bool `bson:"isClientError"`
23+
IsTimeoutError *bool `bson:"isTimeoutError"`
24+
ErrorSubstring *string `bson:"errorContains"`
25+
Code *int32 `bson:"errorCode"`
26+
CodeName *string `bson:"errorCodeName"`
27+
IncludedLabels []string `bson:"errorLabelsContain"`
28+
OmittedLabels []string `bson:"errorLabelsOmit"`
29+
ExpectedResult *bson.RawValue `bson:"expectResult"`
30+
ErrorResponse *bson.Raw `bson:"errorResponse"`
31+
WriteConcernErrors []bson.Raw `bson:"writeConcernErrors"`
3132
}
3233

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

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
{
2+
"description": "unacknowledged-client-bulkWrite",
3+
"schemaVersion": "1.7",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "8.0",
7+
"serverless": "forbid"
8+
}
9+
],
10+
"createEntities": [
11+
{
12+
"client": {
13+
"id": "client",
14+
"useMultipleMongoses": false,
15+
"observeEvents": [
16+
"commandStartedEvent",
17+
"commandSucceededEvent",
18+
"commandFailedEvent"
19+
],
20+
"uriOptions": {
21+
"w": 0
22+
}
23+
}
24+
},
25+
{
26+
"database": {
27+
"id": "database",
28+
"client": "client",
29+
"databaseName": "command-monitoring-tests"
30+
}
31+
},
32+
{
33+
"collection": {
34+
"id": "collection",
35+
"database": "database",
36+
"collectionName": "test"
37+
}
38+
}
39+
],
40+
"initialData": [
41+
{
42+
"collectionName": "test",
43+
"databaseName": "command-monitoring-tests",
44+
"documents": [
45+
{
46+
"_id": 1,
47+
"x": 11
48+
},
49+
{
50+
"_id": 2,
51+
"x": 22
52+
},
53+
{
54+
"_id": 3,
55+
"x": 33
56+
}
57+
]
58+
}
59+
],
60+
"_yamlAnchors": {
61+
"namespace": "command-monitoring-tests.test"
62+
},
63+
"tests": [
64+
{
65+
"description": "A successful mixed client bulkWrite",
66+
"operations": [
67+
{
68+
"object": "client",
69+
"name": "clientBulkWrite",
70+
"arguments": {
71+
"models": [
72+
{
73+
"insertOne": {
74+
"namespace": "command-monitoring-tests.test",
75+
"document": {
76+
"_id": 4,
77+
"x": 44
78+
}
79+
}
80+
},
81+
{
82+
"updateOne": {
83+
"namespace": "command-monitoring-tests.test",
84+
"filter": {
85+
"_id": 3
86+
},
87+
"update": {
88+
"$set": {
89+
"x": 333
90+
}
91+
}
92+
}
93+
}
94+
],
95+
"ordered": false
96+
},
97+
"expectResult": {
98+
"insertedCount": {
99+
"$$unsetOrMatches": 0
100+
},
101+
"upsertedCount": {
102+
"$$unsetOrMatches": 0
103+
},
104+
"matchedCount": {
105+
"$$unsetOrMatches": 0
106+
},
107+
"modifiedCount": {
108+
"$$unsetOrMatches": 0
109+
},
110+
"deletedCount": {
111+
"$$unsetOrMatches": 0
112+
},
113+
"insertResults": {
114+
"$$unsetOrMatches": {}
115+
},
116+
"updateResults": {
117+
"$$unsetOrMatches": {}
118+
},
119+
"deleteResults": {
120+
"$$unsetOrMatches": {}
121+
}
122+
}
123+
},
124+
{
125+
"object": "collection",
126+
"name": "find",
127+
"arguments": {
128+
"filter": {}
129+
},
130+
"expectResult": [
131+
{
132+
"_id": 1,
133+
"x": 11
134+
},
135+
{
136+
"_id": 2,
137+
"x": 22
138+
},
139+
{
140+
"_id": 3,
141+
"x": 333
142+
},
143+
{
144+
"_id": 4,
145+
"x": 44
146+
}
147+
]
148+
}
149+
],
150+
"expectEvents": [
151+
{
152+
"client": "client",
153+
"ignoreExtraEvents": true,
154+
"events": [
155+
{
156+
"commandStartedEvent": {
157+
"commandName": "bulkWrite",
158+
"databaseName": "admin",
159+
"command": {
160+
"bulkWrite": 1,
161+
"errorsOnly": true,
162+
"ordered": false,
163+
"ops": [
164+
{
165+
"insert": 0,
166+
"document": {
167+
"_id": 4,
168+
"x": 44
169+
}
170+
},
171+
{
172+
"update": 0,
173+
"filter": {
174+
"_id": 3
175+
},
176+
"updateMods": {
177+
"$set": {
178+
"x": 333
179+
}
180+
},
181+
"multi": false
182+
}
183+
],
184+
"nsInfo": [
185+
{
186+
"ns": "command-monitoring-tests.test"
187+
}
188+
]
189+
}
190+
}
191+
},
192+
{
193+
"commandSucceededEvent": {
194+
"commandName": "bulkWrite",
195+
"reply": {
196+
"ok": 1,
197+
"nInserted": {
198+
"$$exists": false
199+
},
200+
"nMatched": {
201+
"$$exists": false
202+
},
203+
"nModified": {
204+
"$$exists": false
205+
},
206+
"nUpserted": {
207+
"$$exists": false
208+
},
209+
"nDeleted": {
210+
"$$exists": false
211+
}
212+
}
213+
}
214+
}
215+
]
216+
}
217+
]
218+
}
219+
]
220+
}

0 commit comments

Comments
 (0)