diff options
author | Anton Korshunov <anton.korshunov@mongodb.com> | 2019-08-26 10:36:42 +0000 |
---|---|---|
committer | Anton Korshunov <anton.korshunov@mongodb.com> | 2019-08-26 21:25:18 +0100 |
commit | 22d63982bdd3f99e07dcb69834960fb4042eba69 (patch) | |
tree | 340c098811a2ee8ac56ffd85dcf08ea7d1e86438 /jstests/aggregation | |
parent | cc4c4b31eaf48c5cf54574e27d5717b2bb186a8e (diff) | |
download | mongo-22d63982bdd3f99e07dcb69834960fb4042eba69.tar.gz |
SERVER-42756 $multiply operator may return with or w/o an error depending on whether pipeline optimisation is enabled
(cherry picked from commit aaa9874e04dbc2a4a33aeb7bfad9bee60f7145e0)
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/bugs/server42756.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/server42756.js b/jstests/aggregation/bugs/server42756.js new file mode 100644 index 00000000000..01e22361b61 --- /dev/null +++ b/jstests/aggregation/bugs/server42756.js @@ -0,0 +1,52 @@ +// SERVER-42756 Test that commutative arithmetic operations with special arguments doesn't violate +// commutativity. +(function() { +"use strict"; + +const coll = db[jsTest.name()]; +coll.drop(); +const numbers = [1.0, NumberInt("1"), NumberLong("1"), NumberDecimal("1.0")]; +const specials = [{val: NaN, path: "$nan"}, {val: Infinity, path: "$inf"}]; + +assert.commandWorked(coll.insert({inf: Infinity, nan: NaN})); + +["off", "alwaysOn"].forEach((mode) => { + assert.commandWorked( + db.adminCommand({configureFailPoint: 'disablePipelineOptimization', mode: mode})); + + // TODO SERVER-43034: include $add and $sum. + ["$multiply"].forEach((op) => { + (function testCommutativityWithConstArguments() { + specials.forEach((special) => { + numbers.forEach((num) => { + const expected = [{ + a: (num instanceof NumberDecimal ? NumberDecimal(special.val) : special.val) + }]; + assert.eq(expected, + coll.aggregate([{$project: {a: {[op]: [special.val, num]}, _id: 0}}]) + .toArray()); + assert.eq(expected, + coll.aggregate([{$project: {a: {[op]: [num, special.val]}, _id: 0}}]) + .toArray()); + }); + }); + })(); + + (function testCommutativityWithNonConstArgument() { + specials.forEach((special) => { + numbers.forEach((num) => { + const expected = [{ + a: (num instanceof NumberDecimal ? NumberDecimal(special.val) : special.val) + }]; + assert.eq(expected, + coll.aggregate([{$project: {a: {[op]: [special.path, num]}, _id: 0}}]) + .toArray()); + assert.eq(expected, + coll.aggregate([{$project: {a: {[op]: [num, special.path]}, _id: 0}}]) + .toArray()); + }); + }); + })(); + }); +}); +})(); |