Skip to content

Commit

Permalink
Add more tests for sorting pre-epoch dates. SERVER-405 & QA-40.
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrody committed Aug 25, 2011
1 parent 8d4bf50 commit 812e49a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
48 changes: 48 additions & 0 deletions jstests/sort10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// signed dates check
t = db.sort2;

var opts = {};
if (Math.random() < 0.3) {
opts.background = true;

This comment has been minimized.

Copy link
@nehresma

nehresma Aug 25, 2011

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.

This comment has been minimized.

Copy link
@stbrody

stbrody Aug 25, 2011

Author Contributor

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

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)
16 changes: 0 additions & 16 deletions jstests/sort2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
}

0 comments on commit 812e49a

Please sign in to comment.