Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add more tests for sorting pre-epoch dates. SERVER-405 & QA-40.

  • Loading branch information...
commit 812e49a673293f34a09f091cb5e9124cc5685c6d 1 parent 8d4bf50
@stbrody stbrody authored
Showing with 48 additions and 16 deletions.
  1. +48 −0 jstests/sort10.js
  2. +0 −16 jstests/sort2.js
View
48 jstests/sort10.js
@@ -0,0 +1,48 @@
+// signed dates check
+t = db.sort2;
+
+var opts = {};
+if (Math.random() < 0.3) {
+ opts.background = true;

It seems odd to me to have non deterministic tests. This code seems like it could lead to a test failing one time and succeeding when you try it again.

@stbrody Collaborator
stbrody added a note

I agree! Just added 1450e4c to remove the non-determinism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ printjson(opts);
+}
+t.drop();
+t.insert({ x: new Date(50000) });
+t.insert({ x: new Date(-50) });
+var d = new Date(-50);
+for (var pass = 0; pass < 2; pass++) {
+ assert(t.find().sort({x:1})[0].x.valueOf() == d.valueOf());
+ t.ensureIndex({ x: 1 }, opts);
+ t.insert({ x: new Date() });
+}
+
+
+
+function checkSorting(dates, sortOrder) {
+ cur = t.find().sort({x:sortOrder});
+ assert.eq(dates.length, cur.count(), "Incorrect number of results returned");
+ index = 0;
+ while (cur.hasNext()) {
+ date = cur.next().x;
+ assert.eq(dates[index].valueOf(), date.valueOf());
+ index++;
+ }
+}
+
+t.drop();
+dates = [new Date(-5000000000000), new Date(5000000000000), new Date(0), new Date(5), new Date(-5)];
+for (var i = 0; i < dates.length; i++) {
+ t.insert({x:dates[i]});
+}
+dates.sort(function(a,b){return a - b});
+reverseDates = dates.slice(0).reverse()
+
+checkSorting(dates, 1)
+checkSorting(reverseDates, -1)
+t.ensureIndex({x:1})
+checkSorting(dates, 1)
+checkSorting(reverseDates, -1)
+t.dropIndexes()
+t.ensureIndex({x:-1})
+checkSorting(dates, 1)
+checkSorting(reverseDates, -1)
View
16 jstests/sort2.js
@@ -30,19 +30,3 @@ for (var pass = 0; pass < 2; pass++) {
}
t.ensureIndex({ x : 1 });
}
-
-// signed dates check
-var opts = {};
-if (Math.random() < 0.3) {
- opts.background = true;
- printjson(opts);
-}
-t.drop();
-t.insert({ x: new Date(50000) });
-t.insert({ x: new Date(-50) });
-var d = new Date(-50);
-for (var pass = 0; pass < 2; pass++) {
- assert(t.find().sort({x:1})[0].x.valueOf() == d.valueOf());
- t.ensureIndex({ x: 1 }, opts);
- t.insert({ x: new Date() });
-}
Please sign in to comment.
Something went wrong with that request. Please try again.