diff options
author | vrachev <vlad.rachev@mongodb.com> | 2018-12-13 14:19:26 -0500 |
---|---|---|
committer | vrachev <vlad.rachev@mongodb.com> | 2018-12-13 15:51:33 -0500 |
commit | 7c59c0287705363f4251d13a9929fe7cc7e1a2d8 (patch) | |
tree | cf75557918c9ac2f789d5710b1d62f4d9ae263cd /jstests/sharding | |
parent | 5beb7c7b1b6534e7b3d570ddc775a1fa7094dbb0 (diff) | |
download | mongo-7c59c0287705363f4251d13a9929fe7cc7e1a2d8.tar.gz |
SERVER-36403 Cluster aggregation error message should indicate which shard(s) raised an error
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/agg_error_reports_shard_host_and_port.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/jstests/sharding/agg_error_reports_shard_host_and_port.js b/jstests/sharding/agg_error_reports_shard_host_and_port.js new file mode 100644 index 00000000000..3a73c1d2493 --- /dev/null +++ b/jstests/sharding/agg_error_reports_shard_host_and_port.js @@ -0,0 +1,34 @@ +// Tests that an aggregation error which occurs on a sharded collection will send an error message +// containing the host and port of the shard where the error occurred. +(function() { + "use strict"; + + load("jstests/aggregation/extras/utils.js"); // For assertErrMsgContains. + + const st = new ShardingTest({shards: 2, config: 1}); + + const mongosDb = st.s.getDB(jsTestName()); + const coll = mongosDb.getCollection("foo"); + + // Enable sharding on the test DB and ensure its primary is shard 0. + assert.commandWorked(mongosDb.adminCommand({enableSharding: mongosDb.getName()})); + st.ensurePrimaryShard(mongosDb.getName(), st.rs0.getURL()); + + // Shard the collection. + coll.drop(); + st.shardColl(coll, {_id: 1}, {_id: 0}, {_id: 1}); + + assert.commandWorked(coll.insert({_id: 0})); + + // Run an aggregation which will fail on shard 1, and verify that the error message contains + // the host and port of the shard that failed. + // We need to be careful here to involve some data in the computation that is actually + // sent to the shard before failing (i.e. "$_id") so that mongos doesn't short-curcuit and + // fail during optimization. + const pipe = [{$project: {a: {$divide: ["$_id", 0]}}}]; + const divideByZeroErrorCode = 16608; + + assertErrMsgContains(coll, pipe, divideByZeroErrorCode, st.rs1.getPrimary().host); + + st.stop(); +}()); |