Skip to content

Commit d4f2ea1

Browse files
authored
SWIFT-1304 Allow hint for unacknowledged writes (#765)
1 parent 7ef35aa commit d4f2ea1

File tree

38 files changed

+4730
-1650
lines changed

38 files changed

+4730
-1650
lines changed

Tests/MongoSwiftSyncTests/CrudTests.swift

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,7 @@ final class CrudTests: MongoSwiftTestCase {
9292
asType: UnifiedTestFile.self
9393
)
9494
let runner = try UnifiedTestRunner()
95-
var skipList: [String: [String]] = [
96-
// libmongoc chose not to implement CDRIVER-3630 in anticipation of DRIVERS-1340,
97-
// so we cannot pass these tests for now.
98-
// TODO: DRIVERS-1340 unskip
99-
"unacknowledged-findOneAndUpdate-hint-clientError": ["*"],
100-
"unacknowledged-updateMany-hint-clientError": ["*"],
101-
"unacknowledged-updateOne-hint-clientError": ["*"],
102-
"unacknowledged-deleteOne-hint-clientError": ["*"],
103-
"unacknowledged-deleteMany-hint-clientError": ["*"],
104-
"unacknowledged-replaceOne-hint-clientError": ["*"],
105-
"unacknowledged-findOneAndReplace-hint-clientError": ["*"],
106-
"unacknowledged-findOneAndDelete-hint-clientError": ["*"],
107-
"unacknowledged-bulkWrite-delete-hint-clientError": ["*"],
108-
"unacknowledged-bulkWrite-update-hint-clientError": ["*"],
109-
"unacknowledged-bulkWrite-replace-hint-clientError": ["*"]
110-
]
111-
// Skipping due to a bug in server latest. TODO: SWIFT-1359 unskip
112-
let client = try MongoClient.makeTestClient()
113-
if try client.serverVersion() >= ServerVersion(major: 5, minor: 1, patch: 0)
114-
&& client.topologyType().isSharded
115-
{
116-
skipList["aggregate-out-readConcern"] = ["readConcern available with out stage"]
117-
}
118-
try runner.runFiles(files.map { $0.1 }, skipTests: skipList)
95+
try runner.runFiles(files.map { $0.1 })
11996
}
12097
}
12198

Tests/MongoSwiftSyncTests/UnifiedTestRunner/UnifiedCollectionOperations.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct UnifiedFindOneAndReplace: UnifiedOperationProtocol {
266266
options: options,
267267
session: session
268268
) else {
269-
return .unacknowledgedWrite
269+
return .none
270270
}
271271
return .rootDocument(result)
272272
}
@@ -327,7 +327,7 @@ struct UnifiedFindOneAndUpdate: UnifiedOperationProtocol {
327327
if let doc = result {
328328
return .rootDocument(doc)
329329
} else {
330-
return .unacknowledgedWrite
330+
return .none
331331
}
332332
}
333333
}
@@ -358,7 +358,7 @@ struct UnifiedFindOneAndDelete: UnifiedOperationProtocol {
358358
func execute(on object: UnifiedOperation.Object, context: Context) throws -> UnifiedOperationResult {
359359
let collection = try context.entities.getEntity(from: object).asCollection()
360360
guard let result = try collection.findOneAndDelete(filter, options: self.options) else {
361-
return .unacknowledgedWrite
361+
return .none
362362
}
363363
return .rootDocument(result)
364364
}
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
{
2+
"description": "bulkWrite-deleteMany-hint-unacknowledged",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database0",
16+
"client": "client0",
17+
"databaseName": "db0"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection0",
23+
"database": "database0",
24+
"collectionName": "coll0",
25+
"collectionOptions": {
26+
"writeConcern": {
27+
"w": 0
28+
}
29+
}
30+
}
31+
}
32+
],
33+
"initialData": [
34+
{
35+
"collectionName": "coll0",
36+
"databaseName": "db0",
37+
"documents": [
38+
{
39+
"_id": 1,
40+
"x": 11
41+
},
42+
{
43+
"_id": 2,
44+
"x": 22
45+
},
46+
{
47+
"_id": 3,
48+
"x": 33
49+
}
50+
]
51+
}
52+
],
53+
"tests": [
54+
{
55+
"description": "Unacknowledged deleteMany with hint string fails with client-side error on pre-4.4 server",
56+
"runOnRequirements": [
57+
{
58+
"maxServerVersion": "4.2.99"
59+
}
60+
],
61+
"operations": [
62+
{
63+
"object": "collection0",
64+
"name": "bulkWrite",
65+
"arguments": {
66+
"requests": [
67+
{
68+
"deleteMany": {
69+
"filter": {
70+
"_id": {
71+
"$gt": 1
72+
}
73+
},
74+
"hint": "_id_"
75+
}
76+
}
77+
]
78+
},
79+
"expectError": {
80+
"isClientError": true
81+
}
82+
}
83+
],
84+
"expectEvents": [
85+
{
86+
"client": "client0",
87+
"events": []
88+
}
89+
]
90+
},
91+
{
92+
"description": "Unacknowledged deleteMany with hint document fails with client-side error on pre-4.4 server",
93+
"runOnRequirements": [
94+
{
95+
"maxServerVersion": "4.2.99"
96+
}
97+
],
98+
"operations": [
99+
{
100+
"object": "collection0",
101+
"name": "bulkWrite",
102+
"arguments": {
103+
"requests": [
104+
{
105+
"deleteMany": {
106+
"filter": {
107+
"_id": {
108+
"$gt": 1
109+
}
110+
},
111+
"hint": {
112+
"_id": 1
113+
}
114+
}
115+
}
116+
]
117+
},
118+
"expectError": {
119+
"isClientError": true
120+
}
121+
}
122+
],
123+
"expectEvents": [
124+
{
125+
"client": "client0",
126+
"events": []
127+
}
128+
]
129+
},
130+
{
131+
"description": "Unacknowledged deleteMany with hint string on 4.4+ server",
132+
"runOnRequirements": [
133+
{
134+
"minServerVersion": "4.4.0"
135+
}
136+
],
137+
"operations": [
138+
{
139+
"object": "collection0",
140+
"name": "bulkWrite",
141+
"arguments": {
142+
"requests": [
143+
{
144+
"deleteMany": {
145+
"filter": {
146+
"_id": {
147+
"$gt": 1
148+
}
149+
},
150+
"hint": "_id_"
151+
}
152+
}
153+
]
154+
},
155+
"expectResult": {
156+
"$$unsetOrMatches": {
157+
"acknowledged": {
158+
"$$unsetOrMatches": false
159+
}
160+
}
161+
}
162+
}
163+
],
164+
"expectEvents": [
165+
{
166+
"client": "client0",
167+
"events": [
168+
{
169+
"commandStartedEvent": {
170+
"command": {
171+
"delete": "coll0",
172+
"deletes": [
173+
{
174+
"q": {
175+
"_id": {
176+
"$gt": 1
177+
}
178+
},
179+
"hint": {
180+
"$$type": [
181+
"string",
182+
"object"
183+
]
184+
},
185+
"limit": 0
186+
}
187+
],
188+
"writeConcern": {
189+
"w": 0
190+
}
191+
}
192+
}
193+
}
194+
]
195+
}
196+
]
197+
},
198+
{
199+
"description": "Unacknowledged deleteMany with hint document on 4.4+ server",
200+
"runOnRequirements": [
201+
{
202+
"minServerVersion": "4.4.0"
203+
}
204+
],
205+
"operations": [
206+
{
207+
"object": "collection0",
208+
"name": "bulkWrite",
209+
"arguments": {
210+
"requests": [
211+
{
212+
"deleteMany": {
213+
"filter": {
214+
"_id": {
215+
"$gt": 1
216+
}
217+
},
218+
"hint": {
219+
"_id": 1
220+
}
221+
}
222+
}
223+
]
224+
},
225+
"expectResult": {
226+
"$$unsetOrMatches": {
227+
"acknowledged": {
228+
"$$unsetOrMatches": false
229+
}
230+
}
231+
}
232+
}
233+
],
234+
"expectEvents": [
235+
{
236+
"client": "client0",
237+
"events": [
238+
{
239+
"commandStartedEvent": {
240+
"command": {
241+
"delete": "coll0",
242+
"deletes": [
243+
{
244+
"q": {
245+
"_id": {
246+
"$gt": 1
247+
}
248+
},
249+
"hint": {
250+
"$$type": [
251+
"string",
252+
"object"
253+
]
254+
},
255+
"limit": 0
256+
}
257+
],
258+
"writeConcern": {
259+
"w": 0
260+
}
261+
}
262+
}
263+
}
264+
]
265+
}
266+
]
267+
}
268+
]
269+
}

0 commit comments

Comments
 (0)