From 22d63982bdd3f99e07dcb69834960fb4042eba69 Mon Sep 17 00:00:00 2001 From: Anton Korshunov Date: Mon, 26 Aug 2019 10:36:42 +0000 Subject: SERVER-42756 $multiply operator may return with or w/o an error depending on whether pipeline optimisation is enabled (cherry picked from commit aaa9874e04dbc2a4a33aeb7bfad9bee60f7145e0) --- jstests/aggregation/bugs/server42756.js | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 jstests/aggregation/bugs/server42756.js (limited to 'jstests/aggregation') 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()); + }); + }); + })(); + }); +}); +})(); -- cgit v1.2.1