diff options
author | Gabriel Russell <gabriel.russell@mongodb.com> | 2017-09-05 12:14:27 -0400 |
---|---|---|
committer | Gabriel Russell <gabriel.russell@mongodb.com> | 2017-09-21 15:29:58 -0400 |
commit | 8beb002326a5fdd82c694497b7ebcb52a593a3d3 (patch) | |
tree | 5fefa9a1b037dedab30a81abc6bfa3193b564df2 /jstests/noPassthrough | |
parent | daefad8112937c847282a661392179b9afab0b87 (diff) | |
download | mongo-8beb002326a5fdd82c694497b7ebcb52a593a3d3.tar.gz |
SERVER-28336 endSessions command
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/end_sessions_command.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/jstests/noPassthrough/end_sessions_command.js b/jstests/noPassthrough/end_sessions_command.js new file mode 100644 index 00000000000..3d6ae307a52 --- /dev/null +++ b/jstests/noPassthrough/end_sessions_command.js @@ -0,0 +1,70 @@ +(function() { + "use script"; + + var res; + var refresh = {refreshLogicalSessionCacheNow: 1}; + var startSession = {startSession: 1}; + + // Start up a standalone server. + var conn = MongoRunner.runMongod({nojournal: ""}); + var admin = conn.getDB("admin"); + + // Trigger an initial refresh, as a sanity check. + res = admin.runCommand(refresh); + assert.commandWorked(res, "failed to refresh"); + + var sessions = []; + for (var i = 0; i < 20; i++) { + res = admin.runCommand(startSession); + assert.commandWorked(res, "unable to start session"); + sessions.push(res); + } + + res = admin.runCommand(refresh); + assert.commandWorked(res, "failed to refresh"); + + assert.eq(admin.system.sessions.count(), 20, "refresh should have written 20 session records"); + + var endSessionsIds = []; + for (var i = 0; i < 10; i++) { + endSessionsIds.push(sessions[i].id); + } + res = admin.runCommand({endSessions: endSessionsIds}); + assert.commandWorked(res, "failed to end sessions"); + + res = admin.runCommand(refresh); + assert.commandWorked(res, "failed to refresh"); + + assert.eq(admin.system.sessions.count(), + 10, + "endSessions and refresh should result in 10 remaining sessions"); + + // double delete the remaining 10 + endSessionsIds = []; + for (var i = 10; i < 20; i++) { + endSessionsIds.push(sessions[i].id); + endSessionsIds.push(sessions[i].id); + } + + res = admin.runCommand({endSessions: endSessionsIds}); + assert.commandWorked(res, "failed to end sessions"); + + res = admin.runCommand(refresh); + assert.commandWorked(res, "failed to refresh"); + + assert.eq(admin.system.sessions.count(), + 0, + "endSessions and refresh should result in 0 remaining sessions"); + + // delete some sessions that were never created + res = admin.runCommand({ + endSessions: [ + {"id": UUID("bacb219c-214c-47f9-a94a-6c7f434b3bae")}, + {"id": UUID("bacb219c-214c-47f9-a94a-6c7f434b3baf")} + ] + }); + + res = admin.runCommand(refresh); + assert.commandWorked(res, "failed to refresh"); + +}()); |