summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bradford <david.bradford@mongodb.com>2018-02-15 15:23:13 -0500
committerDavid Bradford <david.bradford@mongodb.com>2018-02-15 15:23:13 -0500
commitcaf6f27ec26a5b0d325e2fcbad39d0239f798a43 (patch)
treeefc13713365866c58e0ea0fd99c56448dcc4923c
parent6bd287f8805027ae88f2d22df0bb1af3b6d6753b (diff)
downloadmongo-caf6f27ec26a5b0d325e2fcbad39d0239f798a43.tar.gz
SERVER-33034: Fix tests with bad assertions
-rw-r--r--jstests/aggregation/bugs/server25590.js16
-rw-r--r--jstests/auth/user_defined_roles_on_secondaries.js18
-rw-r--r--jstests/core/apitest_dbcollection.js2
-rw-r--r--jstests/core/bulk_legacy_enforce_gle.js2
-rw-r--r--jstests/core/fm4.js12
-rw-r--r--jstests/core/geo_s2exact.js4
-rw-r--r--jstests/core/geo_s2near.js8
-rw-r--r--jstests/core/opcounters_active.js10
-rw-r--r--jstests/core/views/views_all_commands.js8
-rw-r--r--jstests/core/views/views_creation.js2
-rw-r--r--jstests/core/write_result.js4
-rw-r--r--jstests/replsets/initial_sync_replSetGetStatus.js4
-rw-r--r--jstests/replsets/slavedelay1.js3
-rw-r--r--jstests/replsets/slaveok_read_pref.js5
-rw-r--r--jstests/replsets/sync2.js2
-rw-r--r--jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js4
16 files changed, 52 insertions, 52 deletions
diff --git a/jstests/aggregation/bugs/server25590.js b/jstests/aggregation/bugs/server25590.js
index cc85446b683..329ae808a2c 100644
--- a/jstests/aggregation/bugs/server25590.js
+++ b/jstests/aggregation/bugs/server25590.js
@@ -8,12 +8,12 @@
assert.writeOK(coll.insert({}));
- assert.commandFailed(db.runCommand({aggregate: coll.getName(), pipeline: 1}),
- ErrorCodes.TypeMismatch);
- assert.commandFailed(db.runCommand({aggregate: coll.getName(), pipeline: {}}),
- ErrorCodes.TypeMismatch);
- assert.commandFailed(db.runCommand({aggregate: coll.getName(), pipeline: [1, 2]}),
- ErrorCodes.TypeMismatch);
- assert.commandFailed(db.runCommand({aggregate: coll.getName(), pipeline: [1, null]}),
- ErrorCodes.TypeMismatch);
+ assert.commandFailedWithCode(db.runCommand({aggregate: coll.getName(), pipeline: 1}),
+ ErrorCodes.TypeMismatch);
+ assert.commandFailedWithCode(db.runCommand({aggregate: coll.getName(), pipeline: {}}),
+ ErrorCodes.TypeMismatch);
+ assert.commandFailedWithCode(db.runCommand({aggregate: coll.getName(), pipeline: [1, 2]}),
+ ErrorCodes.TypeMismatch);
+ assert.commandFailedWithCode(db.runCommand({aggregate: coll.getName(), pipeline: [1, null]}),
+ ErrorCodes.TypeMismatch);
})();
diff --git a/jstests/auth/user_defined_roles_on_secondaries.js b/jstests/auth/user_defined_roles_on_secondaries.js
index 354d77e4471..a0d3ac842b1 100644
--- a/jstests/auth/user_defined_roles_on_secondaries.js
+++ b/jstests/auth/user_defined_roles_on_secondaries.js
@@ -46,8 +46,8 @@
if (list[i].role == role.role && list[i].db == role.db)
return;
}
- doassert("Could not find value " + tojson(val) + " in " +
- tojson(list)(msg ? ": " + msg : ""));
+ doassert("Could not find value " + tojson(val) + " in " + tojson(list) +
+ (msg ? ": " + msg : ""));
}
//
@@ -105,10 +105,10 @@
// Verify that both members of the set see the same role graph.
rstest.nodes.forEach(function(node) {
var role = node.getDB("db1").getRole("r3");
- assert.eq(2, role.roles.length, node);
+ assert.eq(2, role.roles.length, tojson(node));
assertListContainsRole(role.roles, {role: "r1", db: "db1"}, node);
assertListContainsRole(role.roles, {role: "r2", db: "db1"}, node);
- assert.eq(3, role.inheritedRoles.length, node);
+ assert.eq(3, role.inheritedRoles.length, tojson(node));
assertListContainsRole(role.inheritedRoles, {role: "r1", db: "db1"}, node);
assertListContainsRole(role.inheritedRoles, {role: "r2", db: "db1"}, node);
assertListContainsRole(role.inheritedRoles, {role: "read", db: "db1"}, node);
@@ -119,7 +119,7 @@
rstest.getPrimary().getDB("db1").grantRolesToRole("r1", ["dbAdmin"], {w: 2});
rstest.nodes.forEach(function(node) {
var role = node.getDB("db1").getRole("r1");
- assert.eq(1, role.roles.length, node);
+ assert.eq(1, role.roles.length, tojson(node));
assertListContainsRole(role.roles, {role: "dbAdmin", db: "db1"});
});
@@ -128,9 +128,9 @@
rstest.nodes.forEach(function(node) {
assert.eq(null, node.getDB("db1").getRole("r2"));
var role = node.getDB("db1").getRole("r3");
- assert.eq(1, role.roles.length, node);
+ assert.eq(1, role.roles.length, tojson(node));
assertListContainsRole(role.roles, {role: "r1", db: "db1"}, node);
- assert.eq(2, role.inheritedRoles.length, node);
+ assert.eq(2, role.inheritedRoles.length, tojson(node));
assertListContainsRole(role.inheritedRoles, {role: "r1", db: "db1"}, node);
assertListContainsRole(role.inheritedRoles, {role: "dbAdmin", db: "db1"}, node);
});
@@ -200,11 +200,11 @@
assert.commandWorked(rstest.getPrimary().getDB("admin").getLastErrorObj(2));
rstest.nodes.forEach(function(node) {
var role = node.getDB("db1").getRole("t1");
- assert.eq(1, role.roles.length, node);
+ assert.eq(1, role.roles.length, tojson(node));
assertListContainsRole(role.roles, {role: "read", db: "db1"}, node);
var role = node.getDB("db1").getRole("t2");
- assert.eq(1, role.roles.length, node);
+ assert.eq(1, role.roles.length, tojson(node));
assertListContainsRole(role.roles, {role: "readWrite", db: "db1"}, node);
});
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());
diff --git a/jstests/replsets/initial_sync_replSetGetStatus.js b/jstests/replsets/initial_sync_replSetGetStatus.js
index abb5e5c563f..a453f33f12a 100644
--- a/jstests/replsets/initial_sync_replSetGetStatus.js
+++ b/jstests/replsets/initial_sync_replSetGetStatus.js
@@ -44,8 +44,8 @@
assert(res.initialSyncStatus,
"Response should have an 'initialSyncStatus' field: " + tojson(res));
- assert.commandFailed(secondary.adminCommand({replSetGetStatus: 1, initialSync: "t"}),
- ErrorCodes.TypeMismatch);
+ assert.commandFailedWithCode(secondary.adminCommand({replSetGetStatus: 1, initialSync: "t"}),
+ ErrorCodes.TypeMismatch);
assert.writeOK(coll.insert({a: 3}));
assert.writeOK(coll.insert({a: 4}));
diff --git a/jstests/replsets/slavedelay1.js b/jstests/replsets/slavedelay1.js
index 2182db9a171..fa47d57462f 100644
--- a/jstests/replsets/slavedelay1.js
+++ b/jstests/replsets/slavedelay1.js
@@ -108,10 +108,9 @@ doTest = function(signal) {
sleep(1000);
}
- // the node should have the document in 15 seconds (20 for some safety against races)
assert.soon(function() {
return conn.getDB(name).foo.findOne({_id: 124}) != null;
- }, 10 * 1000);
+ }, "findOne should complete within default timeout");
replTest.stopSet();
};
diff --git a/jstests/replsets/slaveok_read_pref.js b/jstests/replsets/slaveok_read_pref.js
index d0ddd52472f..cb923324741 100644
--- a/jstests/replsets/slaveok_read_pref.js
+++ b/jstests/replsets/slaveok_read_pref.js
@@ -39,11 +39,12 @@
if (readPref === "primary" || (!readPref && !slaveOk)) {
// Attempting to run the query throws an error of type NotMasterNoSlaveOk.
- const slaveOkErr = assert.throws(() => cursor.itcount(), [], testType);
+ const slaveOkErr = assert.throws(() => cursor.itcount(), [], tojson(testType));
assert.commandFailedWithCode(slaveOkErr, ErrorCodes.NotMasterNoSlaveOk);
} else {
// Succeeds for all non-primary readPrefs, and for no readPref iff slaveOk.
- const docCount = assert.doesNotThrow(() => cursor.itcount(), [], testType);
+ const docCount =
+ assert.doesNotThrow(() => cursor.itcount(), [], tojson(testType));
assert.eq(docCount, 1);
}
}
diff --git a/jstests/replsets/sync2.js b/jstests/replsets/sync2.js
index 69d141346fe..79a1b48fa68 100644
--- a/jstests/replsets/sync2.js
+++ b/jstests/replsets/sync2.js
@@ -30,7 +30,7 @@
assert.soon(function() {
master = replTest.getPrimary();
return master === conns[0];
- }, replTest.kDefaultTimeoutMS, "node 0 did not become primary quickly enough");
+ }, "node 0 should become primary before timeout", replTest.kDefaultTimeoutMS);
replTest.awaitReplication();
jsTestLog("Checking that ops still replicate correctly");
diff --git a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js
index 2a399f279a5..cfbc27ed7d7 100644
--- a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js
+++ b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js
@@ -224,12 +224,12 @@
checkResults: function(res) {
assert.commandWorked(res);
// Expect the command to return correct results, since it will read orphaned data.
- assert.eq(1, res.results.length, res);
+ assert.eq(1, res.results.length, tojson(res));
},
checkAvailableReadConcernResults: function(res) {
assert.commandWorked(res);
// Command is unversioned, so 'available' has no additional effect.
- assert.eq(1, res.results.length, res);
+ assert.eq(1, res.results.length, tojson(res));
},
behavior: "unversioned"
},