diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2020-03-18 15:17:56 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-25 17:40:43 +0000 |
commit | fe79c4ee1dfc8d49ae06c94a927267712b32b011 (patch) | |
tree | a5ddce887802b62fb028c5d707186ebb64effe66 /jstests/aggregation/sources/replaceRoot | |
parent | b36c69c5930d25a8f5ae348a2b2fb24f27f925e6 (diff) | |
download | mongo-fe79c4ee1dfc8d49ae06c94a927267712b32b011.tar.gz |
SERVER-46700 Update tests in aggregation suite to avoid spawning mongod/sharded clusters
Diffstat (limited to 'jstests/aggregation/sources/replaceRoot')
-rw-r--r-- | jstests/aggregation/sources/replaceRoot/address.js | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/jstests/aggregation/sources/replaceRoot/address.js b/jstests/aggregation/sources/replaceRoot/address.js index 051c693110f..224691477d5 100644 --- a/jstests/aggregation/sources/replaceRoot/address.js +++ b/jstests/aggregation/sources/replaceRoot/address.js @@ -1,9 +1,5 @@ /** * $replaceRoot can be used to extract parts of a document; here we test a simple address case. - * @tags: [ - * requires_sharding, - * requires_spawning_own_processes, - * ] */ (function() { @@ -12,9 +8,6 @@ // For arrayEq. load("jstests/aggregation/extras/utils.js"); -const dbName = "test"; -const collName = jsTest.name(); - Random.setRandomSeed(); /** @@ -51,54 +44,42 @@ function generateRandomDocument() { }; } -function doExecutionTest(conn) { - const coll = conn.getDB(dbName).getCollection(collName); - coll.drop(); - - // Insert a bunch of documents of the form above. - const nDocs = 10; - let bulk = coll.initializeUnorderedBulkOp(); - for (let i = 0; i < nDocs; i++) { - bulk.insert(generateRandomDocument()); - } - assert.commandWorked(bulk.execute()); - - // Extract the contents of the address field, and make sure that doing the same - // with replaceRoot yields the correct answer. - // First compute each separately, since we know all of the fields in the address, - // to make sure we have the correct results. - let addressPipe = [{ - $project: { - "_id": 0, - "number": "$address.number", - "street": "$address.street", - "city": "$address.city", - "zip": "$address.zip" - } - }]; - let correctAddresses = coll.aggregate(addressPipe).toArray(); - - // Then compute the same results using $replaceRoot. - let replaceWithResult = coll.aggregate([ - {$replaceRoot: {newRoot: "$address"}}, - {$sort: {city: 1, zip: 1, street: 1, number: 1}} - ]) - .toArray(); +const dbName = "test"; +const collName = jsTest.name(); +const coll = db.getCollection(collName); +coll.drop(); - // Then assert they are the same. - assert( - arrayEq(replaceWithResult, correctAddresses), - "$replaceRoot does not work the same as $project-ing the relevant fields to the top level"); +// Insert a bunch of documents of the form above. +const nDocs = 10; +let bulk = coll.initializeUnorderedBulkOp(); +for (let i = 0; i < nDocs; i++) { + bulk.insert(generateRandomDocument()); } +assert.commandWorked(bulk.execute()); + +// Extract the contents of the address field, and make sure that doing the same +// with replaceRoot yields the correct answer. +// First compute each separately, since we know all of the fields in the address, +// to make sure we have the correct results. +let addressPipe = [{ + $project: { + "_id": 0, + "number": "$address.number", + "street": "$address.street", + "city": "$address.city", + "zip": "$address.zip" + } +}]; +let correctAddresses = coll.aggregate(addressPipe).toArray(); -// Test against the standalone started by resmoke.py. -let conn = db.getMongo(); -doExecutionTest(conn); -print("Success! Standalone execution test for $replaceRoot passed."); +// Then compute the same results using $replaceRoot. +let replaceWithResult = coll.aggregate([ + {$replaceRoot: {newRoot: "$address"}}, + {$sort: {city: 1, zip: 1, street: 1, number: 1}} + ]) + .toArray(); -// Test against a sharded cluster. -let st = new ShardingTest({shards: 2}); -doExecutionTest(st.s0); -st.stop(); -print("Success! Sharding test for $replaceRoot passed."); +// Then assert they are the same. +assert(arrayEq(replaceWithResult, correctAddresses), + "$replaceRoot does not work the same as $project-ing the relevant fields to the top level"); }()); |