diff --git a/test/change_streams/change-streams.json b/test/change_streams/change-streams.json index 5c28b6276..34371ced0 100644 --- a/test/change_streams/change-streams.json +++ b/test/change_streams/change-streams.json @@ -45,7 +45,22 @@ } ], "result": { - "success": [] + "success": [ + { + "_id": "42", + "documentKey": "42", + "operationType": "insert", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "fullDocument": { + "x": { + "$numberInt": "1" + } + } + } + ] } }, { @@ -440,6 +455,358 @@ } ] } + }, + { + "description": "Test insert, update, replace, and delete event types", + "minServerVersion": "3.6.0", + "target": "collection", + "topology": [ + "replicaset" + ], + "changeStreamPipeline": [], + "changeStreamOptions": {}, + "operations": [ + { + "database": "change-stream-tests", + "collection": "test", + "name": "insertOne", + "arguments": { + "document": { + "x": 1 + } + } + }, + { + "database": "change-stream-tests", + "collection": "test", + "name": "updateOne", + "arguments": { + "filter": { + "x": 1 + }, + "update": { + "$set": { + "x": 2 + } + } + } + }, + { + "database": "change-stream-tests", + "collection": "test", + "name": "replaceOne", + "arguments": { + "filter": { + "x": 2 + }, + "replacement": { + "x": 3 + } + } + }, + { + "database": "change-stream-tests", + "collection": "test", + "name": "deleteOne", + "arguments": { + "filter": { + "x": 3 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "aggregate": "test", + "cursor": {}, + "pipeline": [ + { + "$changeStream": { + "fullDocument": "default" + } + } + ] + }, + "command_name": "aggregate", + "database_name": "change-stream-tests" + } + } + ], + "result": { + "success": [ + { + "operationType": "insert", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "fullDocument": { + "x": { + "$numberInt": "1" + } + } + }, + { + "operationType": "update", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "updateDescription": { + "updatedFields": { + "x": { + "$numberInt": "2" + } + } + } + }, + { + "operationType": "replace", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "fullDocument": { + "x": { + "$numberInt": "3" + } + } + }, + { + "operationType": "delete", + "ns": { + "db": "change-stream-tests", + "coll": "test" + } + } + ] + } + }, + { + "description": "Test rename and invalidate event types", + "minServerVersion": "4.0.1", + "target": "collection", + "topology": [ + "replicaset" + ], + "changeStreamPipeline": [], + "changeStreamOptions": {}, + "operations": [ + { + "database": "change-stream-tests", + "collection": "test", + "name": "rename", + "arguments": { + "to": "test2" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "aggregate": "test", + "cursor": {}, + "pipeline": [ + { + "$changeStream": { + "fullDocument": "default" + } + } + ] + }, + "command_name": "aggregate", + "database_name": "change-stream-tests" + } + } + ], + "result": { + "success": [ + { + "operationType": "rename", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "to": { + "db": "change-stream-tests", + "coll": "test2" + } + }, + { + "operationType": "invalidate" + } + ] + } + }, + { + "description": "Test drop and invalidate event types", + "minServerVersion": "4.0.1", + "target": "collection", + "topology": [ + "replicaset" + ], + "changeStreamPipeline": [], + "changeStreamOptions": {}, + "operations": [ + { + "database": "change-stream-tests", + "collection": "test", + "name": "drop" + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "aggregate": "test", + "cursor": {}, + "pipeline": [ + { + "$changeStream": { + "fullDocument": "default" + } + } + ] + }, + "command_name": "aggregate", + "database_name": "change-stream-tests" + } + } + ], + "result": { + "success": [ + { + "operationType": "drop", + "ns": { + "db": "change-stream-tests", + "coll": "test" + } + }, + { + "operationType": "invalidate" + } + ] + } + }, + { + "description": "Test consecutive resume", + "minServerVersion": "4.1.7", + "target": "collection", + "topology": [ + "replicaset" + ], + "changeStreamPipeline": [], + "changeStreamOptions": { + "batchSize": 1 + }, + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "getMore" + ], + "closeConnection": true + } + }, + "operations": [ + { + "database": "change-stream-tests", + "collection": "test", + "name": "insertOne", + "arguments": { + "document": { + "x": 1 + } + } + }, + { + "database": "change-stream-tests", + "collection": "test", + "name": "insertOne", + "arguments": { + "document": { + "x": 2 + } + } + }, + { + "database": "change-stream-tests", + "collection": "test", + "name": "insertOne", + "arguments": { + "document": { + "x": 3 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "aggregate": "test", + "cursor": { + "batchSize": 1 + }, + "pipeline": [ + { + "$changeStream": { + "fullDocument": "default" + } + } + ] + }, + "command_name": "aggregate", + "database_name": "change-stream-tests" + } + } + ], + "result": { + "success": [ + { + "operationType": "insert", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "fullDocument": { + "x": { + "$numberInt": "1" + } + } + }, + { + "operationType": "insert", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "fullDocument": { + "x": { + "$numberInt": "2" + } + } + }, + { + "operationType": "insert", + "ns": { + "db": "change-stream-tests", + "coll": "test" + }, + "fullDocument": { + "x": { + "$numberInt": "3" + } + } + } + ] + } } ] } diff --git a/test/test_change_stream.py b/test/test_change_stream.py index 9bcf4185f..ffc25eba8 100644 --- a/test/test_change_stream.py +++ b/test/test_change_stream.py @@ -750,7 +750,10 @@ def get_change_stream(client, scenario_def, test): def run_operation(client, operation): # Apply specified operations opname = camel_to_snake(operation["name"]) - arguments = operation["arguments"] + arguments = operation.get("arguments", {}) + if opname == 'rename': + # Special case for rename operation. + arguments = {'new_name': arguments["to"]} cmd = getattr(client.get_database( operation["database"]).get_collection( operation["collection"]), opname