diff options
Diffstat (limited to 'jstests/noPassthrough/traffic_reading_legacy.js')
-rw-r--r-- | jstests/noPassthrough/traffic_reading_legacy.js | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/jstests/noPassthrough/traffic_reading_legacy.js b/jstests/noPassthrough/traffic_reading_legacy.js index 9224edf926a..69cda3be58f 100644 --- a/jstests/noPassthrough/traffic_reading_legacy.js +++ b/jstests/noPassthrough/traffic_reading_legacy.js @@ -1,72 +1,70 @@ // tests for the traffic_recording commands. (function() { - var baseName = "jstests_traffic_recording"; +var baseName = "jstests_traffic_recording"; - // Variables for this test - const recordingDir = MongoRunner.toRealDir("$dataDir/traffic_recording/"); - const recordingFile = "recording.txt"; - const recordingFilePath = MongoRunner.toRealDir(recordingDir + "/" + recordingFile); +// Variables for this test +const recordingDir = MongoRunner.toRealDir("$dataDir/traffic_recording/"); +const recordingFile = "recording.txt"; +const recordingFilePath = MongoRunner.toRealDir(recordingDir + "/" + recordingFile); - // Create the recording directory if it does not already exist - mkdir(recordingDir); +// Create the recording directory if it does not already exist +mkdir(recordingDir); - // Create the options and run mongod - var opts = {auth: "", setParameter: "trafficRecordingDirectory=" + recordingDir}; - m = MongoRunner.runMongod(opts); +// Create the options and run mongod +var opts = {auth: "", setParameter: "trafficRecordingDirectory=" + recordingDir}; +m = MongoRunner.runMongod(opts); - // Get the port of the host - var serverPort = m.port; +// Get the port of the host +var serverPort = m.port; - // Set the readMode and writeMode to legacy - m.forceReadMode("legacy"); - m.forceWriteMode("legacy"); +// Set the readMode and writeMode to legacy +m.forceReadMode("legacy"); +m.forceWriteMode("legacy"); - // Create necessary users - adminDB = m.getDB("admin"); - const testDB = m.getDB("test"); - const coll = testDB.getCollection("foo"); - adminDB.createUser({user: "admin", pwd: "pass", roles: jsTest.adminUserRoles}); - adminDB.auth("admin", "pass"); +// Create necessary users +adminDB = m.getDB("admin"); +const testDB = m.getDB("test"); +const coll = testDB.getCollection("foo"); +adminDB.createUser({user: "admin", pwd: "pass", roles: jsTest.adminUserRoles}); +adminDB.auth("admin", "pass"); - // Start recording traffic - assert.commandWorked( - adminDB.runCommand({'startRecordingTraffic': 1, 'filename': 'recording.txt'})); +// Start recording traffic +assert.commandWorked(adminDB.runCommand({'startRecordingTraffic': 1, 'filename': 'recording.txt'})); - // Run a few commands - testDB.runCommand({"serverStatus": 1}); - coll.insert({"name": "foo biz bar"}); - coll.findOne(); - coll.insert({"name": "foo bar"}); - coll.findOne({"name": "foo bar"}); - coll.deleteOne({}); +// Run a few commands +testDB.runCommand({"serverStatus": 1}); +coll.insert({"name": "foo biz bar"}); +coll.findOne(); +coll.insert({"name": "foo bar"}); +coll.findOne({"name": "foo bar"}); +coll.deleteOne({}); - // Stop recording traffic - assert.commandWorked(testDB.runCommand({'stopRecordingTraffic': 1})); +// Stop recording traffic +assert.commandWorked(testDB.runCommand({'stopRecordingTraffic': 1})); - // Shutdown Mongod - MongoRunner.stopMongod(m, null, {user: 'admin', pwd: 'password'}); +// Shutdown Mongod +MongoRunner.stopMongod(m, null, {user: 'admin', pwd: 'password'}); - // Counters - var opCodes = {}; +// Counters +var opCodes = {}; - // Pass filepath to traffic_reader helper method to get recorded info in BSON - var res = convertTrafficRecordingToBSON(recordingFilePath); +// Pass filepath to traffic_reader helper method to get recorded info in BSON +var res = convertTrafficRecordingToBSON(recordingFilePath); - // Iterate through the results and assert the above commands are properly recorded - res.forEach((obj) => { - opCodes[obj["rawop"]["header"]["opcode"]] = - (opCodes[obj["rawop"]["header"]["opcode"]] || 0) + 1; - assert.eq(obj["seenconnectionnum"], 1); - var responseTo = obj["rawop"]["header"]["responseto"]; - if (responseTo == 0) { - assert.eq(obj["destendpoint"], serverPort.toString()); - } else { - assert.eq(obj["srcendpoint"], serverPort.toString()); - } - }); - - // ensure legacy operations worked properly - assert.eq(opCodes[2002], 2); - assert.eq(opCodes[2006], 1); +// Iterate through the results and assert the above commands are properly recorded +res.forEach((obj) => { + opCodes[obj["rawop"]["header"]["opcode"]] = + (opCodes[obj["rawop"]["header"]["opcode"]] || 0) + 1; + assert.eq(obj["seenconnectionnum"], 1); + var responseTo = obj["rawop"]["header"]["responseto"]; + if (responseTo == 0) { + assert.eq(obj["destendpoint"], serverPort.toString()); + } else { + assert.eq(obj["srcendpoint"], serverPort.toString()); + } +}); +// ensure legacy operations worked properly +assert.eq(opCodes[2002], 2); +assert.eq(opCodes[2006], 1); })(); |