Skip to content

Commit 4232672

Browse files
committed
Ignore _id when comparing change stream documents in tests, since _id is intended to be opaque
1 parent aef6137 commit 4232672

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

driver-core/src/test/functional/com/mongodb/operation/AggregateOperationSpecification.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ class AggregateOperationSpecification extends OperationFunctionalSpecification {
203203
getCollectionHelper().insertDocuments(['{_id: 0, a: 0}', '{_id: 1, a: 1}'].collect { BsonDocument.parse(it) })
204204

205205
then:
206-
next(cursor, async) == expected
206+
def next = next(cursor, async).collect { doc ->
207+
doc.remove('_id')
208+
doc
209+
}
210+
next == expected
207211

208212
cleanup:
209213
cursor?.close()
@@ -499,9 +503,6 @@ class AggregateOperationSpecification extends OperationFunctionalSpecification {
499503

500504
private static BsonDocument createExpectedChangeNotification(MongoNamespace namespace, int idValue) {
501505
BsonDocument.parse("""{
502-
"_id": {
503-
"documentKey": {"_id": $idValue}
504-
},
505506
"operationType": "insert",
506507
"fullDocument": {"_id": $idValue, "a": $idValue},
507508
"ns": {"coll": "${namespace.getCollectionName()}", "db": "${namespace.getDatabaseName()}"},

driver-core/src/test/functional/com/mongodb/operation/ChangeStreamOperationSpecification.groovy

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
107107
def expected = insertDocuments(helper, [1, 2])
108108

109109
then:
110-
nextAndClean(cursor, async) == expected
110+
def next = nextAndClean(cursor, async)
111+
next == expected
111112

112113
when:
113114
expected = insertDocuments(helper, [3, 4, 5, 6, 7])
@@ -286,29 +287,25 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
286287
helper.insertDocuments(docs.collect { BsonDocument.parse("{_id: $it, a: $it}") }, WriteConcern.MAJORITY)
287288
docs.collect {
288289
BsonDocument.parse("""{
289-
"_id": {
290-
"documentKey": {"_id": $it}
291-
},
292290
"operationType": "insert",
293291
"fullDocument": {"_id": $it, "a": $it},
294-
"ns": {"coll": "${helper.getNamespace().getCollectionName()}", "db": "${helper.getNamespace().getDatabaseName()}"},
292+
"ns": {"db": "${helper.getNamespace().getDatabaseName()}", "coll": "${helper.getNamespace().getCollectionName()}"},
295293
"documentKey": {"_id": $it}
296294
}""")
297295
}
298296
}
299297

300298
def tryNextAndClean(cursor, boolean async) {
301-
removeTimestampAndUUID(tryNext(cursor, async))
299+
removeId(tryNext(cursor, async))
302300
}
303301

304302
def nextAndClean(cursor, boolean async) {
305-
removeTimestampAndUUID(next(cursor, async))
303+
removeId(next(cursor, async))
306304
}
307305

308-
def removeTimestampAndUUID(List<BsonDocument> next) {
306+
def removeId(List<BsonDocument> next) {
309307
next?.collect { doc ->
310-
doc.getDocument('_id').remove('clusterTime')
311-
doc.getDocument('_id').remove('uuid')
308+
doc.remove('_id')
312309
doc
313310
}
314311
}

0 commit comments

Comments
 (0)