From caf6f27ec26a5b0d325e2fcbad39d0239f798a43 Mon Sep 17 00:00:00 2001 From: David Bradford Date: Thu, 15 Feb 2018 15:23:13 -0500 Subject: SERVER-33034: Fix tests with bad assertions --- jstests/core/apitest_dbcollection.js | 2 +- jstests/core/bulk_legacy_enforce_gle.js | 2 +- jstests/core/fm4.js | 12 ++++++------ jstests/core/geo_s2exact.js | 4 ++-- jstests/core/geo_s2near.js | 8 ++++---- jstests/core/opcounters_active.js | 10 +++++----- jstests/core/views/views_all_commands.js | 8 ++++---- jstests/core/views/views_creation.js | 2 +- jstests/core/write_result.js | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) (limited to 'jstests/core') diff --git a/jstests/core/apitest_dbcollection.js b/jstests/core/apitest_dbcollection.js index 6b90d4de6a9..775abc97272 100644 --- a/jstests/core/apitest_dbcollection.js +++ b/jstests/core/apitest_dbcollection.js @@ -77,7 +77,7 @@ for (i = 0; i < 100; i++) { validateResult.ns, 'incorrect namespace in db.collection.validate() result: ' + tojson(validateResult)); assert(validateResult.valid, 'collection validation failed'); - assert.eq(100, validateResult.nrecords, 11); + assert.eq(100, validateResult.nrecords, "11"); }()); /* diff --git a/jstests/core/bulk_legacy_enforce_gle.js b/jstests/core/bulk_legacy_enforce_gle.js index 473f6a4684d..770734e43bc 100644 --- a/jstests/core/bulk_legacy_enforce_gle.js +++ b/jstests/core/bulk_legacy_enforce_gle.js @@ -115,7 +115,7 @@ res = assert.throws(function() { bulk.execute(); }); - assert.eq(1, res.getWriteErrors().length, res); + assert.eq(1, res.getWriteErrors().length, () => tojson(res)); gle = db.runCommand({getLastError: 1, w: 0}); assert(gle.ok, tojson(gle)); diff --git a/jstests/core/fm4.js b/jstests/core/fm4.js index 6a1aa5a44b5..53ab1005a81 100644 --- a/jstests/core/fm4.js +++ b/jstests/core/fm4.js @@ -3,14 +3,14 @@ t.drop(); t.insert({_id: 1, a: 1, b: 1}); -assert.eq(t.findOne({}, {_id: 1}), {_id: 1}, 1); -assert.eq(t.findOne({}, {_id: 0}), {a: 1, b: 1}, 2); +assert.eq(t.findOne({}, {_id: 1}), {_id: 1}, "1"); +assert.eq(t.findOne({}, {_id: 0}), {a: 1, b: 1}, "2"); -assert.eq(t.findOne({}, {_id: 1, a: 1}), {_id: 1, a: 1}, 3); -assert.eq(t.findOne({}, {_id: 0, a: 1}), {a: 1}, 4); +assert.eq(t.findOne({}, {_id: 1, a: 1}), {_id: 1, a: 1}, "3"); +assert.eq(t.findOne({}, {_id: 0, a: 1}), {a: 1}, "4"); -assert.eq(t.findOne({}, {_id: 0, a: 0}), {b: 1}, 6); -assert.eq(t.findOne({}, {a: 0}), {_id: 1, b: 1}, 5); +assert.eq(t.findOne({}, {_id: 0, a: 0}), {b: 1}, "6"); +assert.eq(t.findOne({}, {a: 0}), {_id: 1, b: 1}, "5"); // not sure if we want to suport this since it is the same as above // assert.eq( t.findOne({}, {_id:1, a:0}), {_id:1, b:1}, 5) diff --git a/jstests/core/geo_s2exact.js b/jstests/core/geo_s2exact.js index 3acd5b68969..2c8571c0830 100644 --- a/jstests/core/geo_s2exact.js +++ b/jstests/core/geo_s2exact.js @@ -4,9 +4,9 @@ t.drop(); function test(geometry) { t.insert({geo: geometry}); - assert.eq(1, t.find({geo: geometry}).itcount(), geometry); + assert.eq(1, t.find({geo: geometry}).itcount(), tojson(geometry)); t.ensureIndex({geo: "2dsphere"}); - assert.eq(1, t.find({geo: geometry}).itcount(), geometry); + assert.eq(1, t.find({geo: geometry}).itcount(), tojson(geometry)); t.dropIndex({geo: "2dsphere"}); } diff --git a/jstests/core/geo_s2near.js b/jstests/core/geo_s2near.js index c045eeb09c0..0306a60adb9 100644 --- a/jstests/core/geo_s2near.js +++ b/jstests/core/geo_s2near.js @@ -60,16 +60,16 @@ assert.throws(function() { res = t.find({"geo": {"$near": {"$geometry": origin, $maxDistance: 2000}}}).limit(10); resNear = db.runCommand( {geoNear: t.getName(), near: [0, 0], num: 10, maxDistance: Math.PI, spherical: true}); -assert.eq(res.itcount(), resNear.results.length, 10); +assert.eq(res.itcount(), resNear.results.length, "10"); res = t.find({"geo": {"$near": {"$geometry": origin}}}).limit(10); resNear = db.runCommand({geoNear: t.getName(), near: [0, 0], num: 10, spherical: true}); -assert.eq(res.itcount(), resNear.results.length, 10); +assert.eq(res.itcount(), resNear.results.length, "10"); // Find all the points! res = t.find({"geo": {"$near": {"$geometry": origin}}}).limit(10000); resNear = db.runCommand({geoNear: t.getName(), near: [0, 0], num: 10000, spherical: true}); -assert.eq(resNear.results.length, res.itcount(), (2 * points) * (2 * points)); +assert.eq(resNear.results.length, res.itcount(), ((2 * points) * (2 * points)).toString()); // longitude goes -180 to 180 // latitude goes -90 to 90 @@ -81,7 +81,7 @@ t.insert({geo: {"type": "Point", "coordinates": [180, 90]}}); t.insert({geo: {"type": "Point", "coordinates": [-180, 90]}}); res = t.find({"geo": {"$near": {"$geometry": origin}}}).limit(10000); resNear = db.runCommand({geoNear: t.getName(), near: [0, 0], num: 10000, spherical: true}); -assert.eq(res.itcount(), resNear.results.length, (2 * points) * (2 * points) + 4); +assert.eq(res.itcount(), resNear.results.length, ((2 * points) * (2 * points) + 4).toString()); function testRadAndDegreesOK(distance) { // Distance for old style points is radians. diff --git a/jstests/core/opcounters_active.js b/jstests/core/opcounters_active.js index c184eab3d1d..283415ba8b1 100644 --- a/jstests/core/opcounters_active.js +++ b/jstests/core/opcounters_active.js @@ -19,15 +19,15 @@ // Test that the serverstatus helper works var result = db.serverStatus(); - assert.neq(undefined, result, result); + assert.neq(undefined, result, tojson(result)); // Test that the metrics tree returns - assert.neq(undefined, result.metrics, result); + assert.neq(undefined, result.metrics, tojson(result)); // Test that the metrics.commands tree returns - assert.neq(undefined, result.metrics.commands, result); + assert.neq(undefined, result.metrics.commands, tojson(result)); // Test that the metrics.commands.serverStatus value is non-zero - assert.neq(0, result.metrics.commands.serverStatus.total, result); + assert.neq(0, result.metrics.commands.serverStatus.total, tojson(result)); // Test that the command returns successfully when no metrics tree is present var result = db.serverStatus({"metrics": 0}); - assert.eq(undefined, result.metrics, result); + assert.eq(undefined, result.metrics, tojson(result)); }()); \ No newline at end of file diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index f918d7ac13a..b961f84f6bf 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -252,7 +252,7 @@ command: function(conn) { function testGetMoreForCommand(cmd) { let res = conn.runCommand(cmd); - assert.commandWorked(res, cmd); + assert.commandWorked(res, tojson(cmd)); let cursor = res.cursor; assert.eq(cursor.ns, "test.view", @@ -262,7 +262,7 @@ let getmoreCmd = {getMore: cursor.id, collection: "view"}; res = conn.runCommand(getmoreCmd); - assert.commandWorked(res, getmoreCmd); + assert.commandWorked(res, tojson(getmoreCmd)); assert.eq("test.view", res.cursor.ns, "expected view namespace in cursor: " + tojson(res)); @@ -317,7 +317,7 @@ cursor: {batchSize: 2} }; let res = conn.runCommand(aggCmd); - assert.commandWorked(res, aggCmd); + assert.commandWorked(res, tojson(aggCmd)); let cursor = res.cursor; assert.eq( cursor.ns, "test.view", "expected view namespace in cursor: " + tojson(cursor)); @@ -328,7 +328,7 @@ // Then check correct execution of the killCursors command. let killCursorsCmd = {killCursors: "view", cursors: [cursor.id]}; res = conn.runCommand(killCursorsCmd); - assert.commandWorked(res, killCursorsCmd); + assert.commandWorked(res, tojson(killCursorsCmd)); let expectedRes = { cursorsKilled: [cursor.id], cursorsNotFound: [], diff --git a/jstests/core/views/views_creation.js b/jstests/core/views/views_creation.js index c4ade5e728e..f8bc752ff73 100644 --- a/jstests/core/views/views_creation.js +++ b/jstests/core/views/views_creation.js @@ -44,7 +44,7 @@ collNames = viewsDB.getCollectionNames().filter((function(coll) { return !coll.startsWith("system."); })); - assert.eq(2, collNames.length, collNames); + assert.eq(2, collNames.length, tojson(collNames)); let res = viewsDB.runCommand({listCollections: 1, filter: {type: "view"}}); assert.commandWorked(res); diff --git a/jstests/core/write_result.js b/jstests/core/write_result.js index dc641501815..4eb1abed2d7 100644 --- a/jstests/core/write_result.js +++ b/jstests/core/write_result.js @@ -119,7 +119,7 @@ printjson(result = coll.update({foo: "bar"}, {$invalid: "expr"})); assert.eq(result.nUpserted, 0); assert.eq(result.nMatched, 0); if (coll.getMongo().writeMode() == "commands") - assert.eq(0, result.nModified, result); + assert.eq(0, result.nModified, tojson(result)); assert(result.getWriteError()); assert(result.getWriteError().errmsg); assert(!result.getUpsertedId()); @@ -138,7 +138,7 @@ printjson(result = coll.update({}, {$bit: {value: {and: NumberInt(0)}}}, {multi: assert.eq(result.nUpserted, 0); assert.eq(result.nMatched, 0); if (coll.getMongo().writeMode() == "commands") - assert.eq(0, result.nModified, result); + assert.eq(0, result.nModified, tojson(result)); assert(result.getWriteError()); assert(result.getWriteError().errmsg); assert(!result.getUpsertedId()); -- cgit v1.2.1