Skip to content

Commit

Permalink
test(aggregation): ensure deterministic order for these tests
Browse files Browse the repository at this point in the history
These tests check the values of the results in an presumed order,
but in sharded environment this cannot be guaranteed. We should
include a `$sort` stage to ensure the ordering.
  • Loading branch information
mbroadst committed Feb 23, 2019
1 parent 1521397 commit d8aed2b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
70 changes: 40 additions & 30 deletions test/functional/aggregation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ describe('Aggregation', function() {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
}
},
{ $sort: { _id: -1 } }
],
function(err, cursor) {
expect(err).to.be.null;
Expand Down Expand Up @@ -190,19 +191,22 @@ describe('Aggregation', function() {
// Execute aggregate, notice the pipeline is expressed as function call parameters
// instead of an Array.
collection.aggregate(
{
$project: {
author: 1,
tags: 1
}
},
{ $unwind: '$tags' },
{
$group: {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
},
[
{
$project: {
author: 1,
tags: 1
}
},
{ $unwind: '$tags' },
{
$group: {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
},
{ $sort: { _id: -1 } }
],
function(err, cursor) {
expect(err).to.be.null;

Expand Down Expand Up @@ -283,19 +287,22 @@ describe('Aggregation', function() {
// Execute aggregate, notice the pipeline is expressed as function call parameters
// instead of an Array.
collection.aggregate(
{
$project: {
author: 1,
tags: 1
}
},
{ $unwind: '$tags' },
{
$group: {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
},
[
{
$project: {
author: 1,
tags: 1
}
},
{ $unwind: '$tags' },
{
$group: {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
},
{ $sort: { _id: -1 } }
],
function(err, cursor) {
expect(err).to.be.null;

Expand Down Expand Up @@ -561,7 +568,8 @@ describe('Aggregation', function() {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
}
},
{ $sort: { _id: -1 } }
],
{
cursor: { batchSize: 1 }
Expand Down Expand Up @@ -747,7 +755,8 @@ describe('Aggregation', function() {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
}
},
{ $sort: { _id: -1 } }
],
{
allowDiskUse: true
Expand Down Expand Up @@ -1105,7 +1114,8 @@ describe('Aggregation', function() {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
}
},
{ $sort: { _id: -1 } }
],
{
cursor: { batchSize: 1 },
Expand Down
5 changes: 3 additions & 2 deletions test/functional/operation_example_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('Operation Examples', function() {
_id: { tags: '$tags' },
authors: { $addToSet: '$author' }
}
}
},
{ $sort: { _id: -1 } }
],
function(err, cursor) {
test.equal(null, err);
Expand Down Expand Up @@ -190,8 +191,8 @@ describe('Operation Examples', function() {
cursor.toArray(function(err, docs) {
test.equal(null, err);
test.equal(2, docs.length);
done();
client.close();
done();
});
});
});
Expand Down

0 comments on commit d8aed2b

Please sign in to comment.