summaryrefslogtreecommitdiff
path: root/jstests/sharding/now_variable_sharding.js
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2020-02-27 17:01:26 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-28 20:25:48 +0000
commit5b58136c5442a21c601a4b5b38a95f15c44ae567 (patch)
tree45bb0216ad2aace9057c2e0695d987c698900d35 /jstests/sharding/now_variable_sharding.js
parentcc7df7d69ff471a1b4e3affcc4d2612577e43ae8 (diff)
downloadmongo-5b58136c5442a21c601a4b5b38a95f15c44ae567.tar.gz
SERVER-45562 Ensure consistent $$NOW value across $unionWith arms
Diffstat (limited to 'jstests/sharding/now_variable_sharding.js')
-rw-r--r--jstests/sharding/now_variable_sharding.js48
1 files changed, 35 insertions, 13 deletions
diff --git a/jstests/sharding/now_variable_sharding.js b/jstests/sharding/now_variable_sharding.js
index 13f9b90e626..f0c545ff99f 100644
--- a/jstests/sharding/now_variable_sharding.js
+++ b/jstests/sharding/now_variable_sharding.js
@@ -1,7 +1,10 @@
/**
* Tests for the $$NOW and $$CLUSTER_TIME system variable on a sharded cluster.
*/
-// @tags: [requires_find_command]
+// @tags: [
+// requires_find_command,
+// requires_fcv_44 # Uses $unionWith.
+// ]
(function() {
"use strict";
@@ -66,12 +69,12 @@ function toResultsArray(queryRes) {
return Array.isArray(queryRes) ? queryRes : queryRes.toArray();
}
-function runTests(query) {
+function runTests({query, expectedNumDocs = numdocs}) {
const results = toResultsArray(query());
- assert.eq(results.length, numdocs);
+ assert.eq(results.length, expectedNumDocs);
// Make sure the values are the same for all documents
- for (let i = 0; i < numdocs; ++i) {
+ for (let i = 0; i < expectedNumDocs; ++i) {
assert.eq(results[0].timeField, results[i].timeField);
}
@@ -79,7 +82,7 @@ function runTests(query) {
sleep(3000);
const resultsLater = toResultsArray(query());
- assert.eq(resultsLater.length, numdocs);
+ assert.eq(resultsLater.length, expectedNumDocs);
// Later results should be later in time.
assert.lte(results[0].timeField, resultsLater[0].timeField);
@@ -107,6 +110,23 @@ function baseCollectionClusterTimeAgg() {
return coll.aggregate([{$addFields: {timeField: "$$CLUSTER_TIME"}}]);
}
+function baseCollectionNowUnion() {
+ return coll.aggregate([
+ {$addFields: {timeField: "$$NOW"}},
+ {$unionWith: {coll: otherColl.getName(), pipeline: [{$addFields: {timeField: "$$NOW"}}]}}
+ ]);
+}
+
+function baseCollectionClusterTimeUnion() {
+ return coll.aggregate([
+ {$addFields: {timeField: "$$CLUSTER_TIME"}},
+ {
+ $unionWith:
+ {coll: otherColl.getName(), pipeline: [{$addFields: {timeField: "$$CLUSTER_TIME"}}]}
+ }
+ ]);
+}
+
function fromViewWithNow() {
return viewWithNow.find();
}
@@ -124,10 +144,11 @@ function withExprClusterTime() {
}
// $$NOW
-runTests(baseCollectionNowFind);
-runTests(baseCollectionNowAgg);
-runTests(fromViewWithNow);
-runTests(withExprNow);
+runTests({query: baseCollectionNowFind});
+runTests({query: baseCollectionNowAgg});
+runTests({query: baseCollectionNowUnion, expectedNumDocs: 2 * numdocs});
+runTests({query: fromViewWithNow});
+runTests({query: withExprNow});
// Test that $$NOW can be used in explain for both find and aggregate.
assert.commandWorked(coll.explain().find({$expr: {$lte: ["$timeField", "$$NOW"]}}).finish());
@@ -135,10 +156,11 @@ assert.commandWorked(viewWithNow.explain().find({$expr: {$eq: ["$timeField", "$$
assert.commandWorked(coll.explain().aggregate([{$addFields: {timeField: "$$NOW"}}]));
// $$CLUSTER_TIME
-runTests(baseCollectionClusterTimeFind);
-runTests(baseCollectionClusterTimeAgg);
-runTests(fromViewWithClusterTime);
-runTests(withExprClusterTime);
+runTests({query: baseCollectionClusterTimeFind});
+runTests({query: baseCollectionClusterTimeAgg});
+runTests({query: baseCollectionClusterTimeUnion, expectedNumDocs: 2 * numdocs});
+runTests({query: fromViewWithClusterTime});
+runTests({query: withExprClusterTime});
// Test that $$CLUSTER_TIME can be used in explain for both find and aggregate.
assert.commandWorked(