From 3273fe9fbeae7572e0faaa2bc22312bac6de2a14 Mon Sep 17 00:00:00 2001 From: Divjot Arora Date: Tue, 14 Jan 2020 13:33:55 -0500 Subject: [PATCH] GODRIVER-1427 Resync sessions spec tests --- data/sessions/dirty-session-errors.json | 315 +++++++++++++++++++++++- data/sessions/dirty-session-errors.yml | 168 +++++++++++++ 2 files changed, 482 insertions(+), 1 deletion(-) diff --git a/data/sessions/dirty-session-errors.json b/data/sessions/dirty-session-errors.json index 9eccff0593..a964b208c5 100644 --- a/data/sessions/dirty-session-errors.json +++ b/data/sessions/dirty-session-errors.json @@ -357,6 +357,149 @@ } } }, + { + "description": "Dirty explicit session is discarded (non-bulk write)", + "clientOptions": { + "retryWrites": true + }, + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "findAndModify" + ], + "closeConnection": true + } + }, + "operations": [ + { + "name": "assertSessionNotDirty", + "object": "testRunner", + "arguments": { + "session": "session0" + } + }, + { + "name": "findOneAndUpdate", + "object": "collection", + "arguments": { + "session": "session0", + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "returnDocument": "Before" + }, + "result": { + "_id": 1 + } + }, + { + "name": "assertSessionDirty", + "object": "testRunner", + "arguments": { + "session": "session0" + } + }, + { + "name": "endSession", + "object": "session0" + }, + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": -1 + } + }, + "result": [] + }, + { + "name": "assertDifferentLsidOnLastTwoCommands", + "object": "testRunner" + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "test", + "query": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "new": false, + "lsid": "session0", + "txnNumber": { + "$numberLong": "1" + }, + "readConcern": null, + "writeConcern": null + }, + "command_name": "findAndModify", + "database_name": "session-tests" + } + }, + { + "command_started_event": { + "command": { + "findAndModify": "test", + "query": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "new": false, + "lsid": "session0", + "txnNumber": { + "$numberLong": "1" + }, + "readConcern": null, + "writeConcern": null + }, + "command_name": "findAndModify", + "database_name": "session-tests" + } + }, + { + "command_started_event": { + "command": { + "find": "test", + "filter": { + "_id": -1 + } + }, + "command_name": "find", + "database_name": "session-tests" + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 1 + } + ] + } + } + }, { "description": "Dirty implicit session is discarded (write)", "clientOptions": { @@ -465,6 +608,128 @@ } } }, + { + "description": "Dirty implicit session is discarded (non-bulk write)", + "clientOptions": { + "retryWrites": true + }, + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "findAndModify" + ], + "closeConnection": true + } + }, + "operations": [ + { + "name": "findOneAndUpdate", + "object": "collection", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "returnDocument": "Before" + }, + "result": { + "_id": 1 + } + }, + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": -1 + } + }, + "result": [] + }, + { + "name": "assertDifferentLsidOnLastTwoCommands", + "object": "testRunner" + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "test", + "query": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "new": false, + "txnNumber": { + "$numberLong": "1" + }, + "readConcern": null, + "writeConcern": null + }, + "command_name": "findAndModify", + "database_name": "session-tests" + } + }, + { + "command_started_event": { + "command": { + "findAndModify": "test", + "query": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "new": false, + "txnNumber": { + "$numberLong": "1" + }, + "readConcern": null, + "writeConcern": null + }, + "command_name": "findAndModify", + "database_name": "session-tests" + } + }, + { + "command_started_event": { + "command": { + "find": "test", + "filter": { + "_id": -1 + } + }, + "command_name": "find", + "database_name": "session-tests" + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 1 + } + ] + } + } + }, { "description": "Dirty implicit session is discarded (read)", "failPoint": { @@ -518,6 +783,54 @@ ] } } + }, + { + "description": "Dirty implicit session is discarded (non-cursor returning read)", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "aggregate" + ], + "closeConnection": true + } + }, + "operations": [ + { + "name": "countDocuments", + "object": "collection", + "arguments": { + "filter": {} + }, + "error": true + }, + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": -1 + } + }, + "result": [] + }, + { + "name": "assertDifferentLsidOnLastTwoCommands", + "object": "testRunner" + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1 + } + ] + } + } } ] -} +} \ No newline at end of file diff --git a/data/sessions/dirty-session-errors.yml b/data/sessions/dirty-session-errors.yml index 32228ecf76..14aeefcb48 100644 --- a/data/sessions/dirty-session-errors.yml +++ b/data/sessions/dirty-session-errors.yml @@ -188,6 +188,82 @@ tests: - {_id: 2} - {_id: 3} + - description: Dirty explicit session is discarded (non-bulk write) + + clientOptions: + retryWrites: true + + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: ["findAndModify"] + closeConnection: true + + operations: + - name: assertSessionNotDirty + object: testRunner + arguments: + session: session0 + - &find_and_update_with_explicit_session + name: findOneAndUpdate + object: collection + arguments: + session: session0 + filter: {_id: 1} + update: + $inc: {x: 1} + returnDocument: Before + result: {_id: 1} + - name: assertSessionDirty + object: testRunner + arguments: + session: session0 + - name: endSession + object: session0 + - *find_with_implicit_session + - name: assertDifferentLsidOnLastTwoCommands + object: testRunner + + expectations: + - command_started_event: + command: + findAndModify: *collection_name + query: {_id: 1} + update: {$inc: {x: 1}} + new: false + lsid: session0 + txnNumber: + $numberLong: "1" + readConcern: + writeConcern: + command_name: findAndModify + database_name: *database_name + - command_started_event: + command: + findAndModify: *collection_name + query: {_id: 1} + update: {$inc: {x: 1}} + new: false + lsid: session0 + txnNumber: + $numberLong: "1" + readConcern: + writeConcern: + command_name: findAndModify + database_name: *database_name + - command_started_event: + command: + find: *collection_name + filter: {_id: -1} + command_name: find + database_name: *database_name + + outcome: + collection: + data: + - {_id: 1, x: 1} + - description: Dirty implicit session is discarded (write) clientOptions: @@ -240,6 +316,69 @@ tests: - {_id: 1} - {_id: 2} + - description: Dirty implicit session is discarded (non-bulk write) + + clientOptions: + retryWrites: true + + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: ["findAndModify"] + closeConnection: true + + operations: + - &find_and_update_with_implicit_session + name: findOneAndUpdate + object: collection + arguments: + filter: {_id: 1} + update: + $inc: {x: 1} + returnDocument: Before + result: {_id: 1} + - *find_with_implicit_session + - name: assertDifferentLsidOnLastTwoCommands + object: testRunner + + expectations: + - command_started_event: + command: + findAndModify: *collection_name + query: {_id: 1} + update: {$inc: {x: 1}} + new: false + txnNumber: + $numberLong: "1" + readConcern: + writeConcern: + command_name: findAndModify + database_name: *database_name + - command_started_event: + command: + findAndModify: *collection_name + query: {_id: 1} + update: {$inc: {x: 1}} + new: false + txnNumber: + $numberLong: "1" + readConcern: + writeConcern: + command_name: findAndModify + database_name: *database_name + - command_started_event: + command: + find: *collection_name + filter: {_id: -1} + command_name: find + database_name: *database_name + + outcome: + collection: + data: + - {_id: 1, x: 1} + - description: Dirty implicit session is discarded (read) # Enable the failpoint with times:2 so that this test can pass with or @@ -270,3 +409,32 @@ tests: collection: data: - {_id: 1} + + - description: Dirty implicit session is discarded (non-cursor returning read) + + # Enable the failpoint with times:2 so that this test can pass with or + # without retryable reads. + failPoint: + configureFailPoint: failCommand + mode: { times: 2 } + data: + failCommands: ["aggregate"] + closeConnection: true + + operations: + - name: countDocuments + object: collection + arguments: + filter: {} + error: true + - *find_with_implicit_session + - name: assertDifferentLsidOnLastTwoCommands + object: testRunner + + # Don't include expectations because a driver may or may not retry the + # count depending on if they have implemented the retryable reads spec. + + outcome: + collection: + data: + - {_id: 1}