From 8beb002326a5fdd82c694497b7ebcb52a593a3d3 Mon Sep 17 00:00:00 2001 From: Gabriel Russell Date: Tue, 5 Sep 2017 12:14:27 -0400 Subject: SERVER-28336 endSessions command --- jstests/noPassthrough/end_sessions_command.js | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 jstests/noPassthrough/end_sessions_command.js (limited to 'jstests/noPassthrough') 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"); + +}()); -- cgit v1.2.1