diff options
Diffstat (limited to 'jstests/replsets/aggregation_write_concern.js')
-rw-r--r-- | jstests/replsets/aggregation_write_concern.js | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/jstests/replsets/aggregation_write_concern.js b/jstests/replsets/aggregation_write_concern.js index 8622fc0f113..807da4bf244 100644 --- a/jstests/replsets/aggregation_write_concern.js +++ b/jstests/replsets/aggregation_write_concern.js @@ -3,47 +3,47 @@ * not wait for the writeConcern specified to be satisfied. */ (function() { - "use strict"; - - load("jstests/libs/write_concern_util.js"); // For stopReplicationOnSecondaries, - // restartReplicationOnSecondaries - const name = "aggregation_write_concern"; - - const replTest = new ReplSetTest({nodes: [{}, {rsConfig: {priority: 0}}]}); - - replTest.startSet(); - replTest.initiate(); - - const testDB = replTest.getPrimary().getDB(name); - const collectionName = "test"; - - // Stop replication and perform a w: 1 write. This will block subsequent 'writeConcern: - // majority' reads if the read command waits on writeConcern. - - stopReplicationOnSecondaries(replTest); - assert.commandWorked( - testDB.runCommand({insert: collectionName, documents: [{_id: 1}], writeConcern: {w: 1}})); - - // A read-only aggregation accepts the writeConcern option but does not wait for it. - let res = assert.commandWorked(testDB.runCommand({ - aggregate: collectionName, - pipeline: [{$match: {_id: 1}}], - cursor: {}, - writeConcern: {w: "majority"} - })); - assert(res.cursor.firstBatch.length); - assert.eq(res.cursor.firstBatch[0], {_id: 1}); - - // An aggregation pipeline that writes will block on writeConcern. - assert.commandFailedWithCode(testDB.runCommand({ - aggregate: collectionName, - pipeline: [{$match: {_id: 1}}, {$out: collectionName + "_out"}], - cursor: {}, - writeConcern: {w: "majority", wtimeout: 1000} - }), - ErrorCodes.WriteConcernFailed); - - restartReplicationOnSecondaries(replTest); - replTest.awaitLastOpCommitted(); - replTest.stopSet(); +"use strict"; + +load("jstests/libs/write_concern_util.js"); // For stopReplicationOnSecondaries, + // restartReplicationOnSecondaries +const name = "aggregation_write_concern"; + +const replTest = new ReplSetTest({nodes: [{}, {rsConfig: {priority: 0}}]}); + +replTest.startSet(); +replTest.initiate(); + +const testDB = replTest.getPrimary().getDB(name); +const collectionName = "test"; + +// Stop replication and perform a w: 1 write. This will block subsequent 'writeConcern: +// majority' reads if the read command waits on writeConcern. + +stopReplicationOnSecondaries(replTest); +assert.commandWorked( + testDB.runCommand({insert: collectionName, documents: [{_id: 1}], writeConcern: {w: 1}})); + +// A read-only aggregation accepts the writeConcern option but does not wait for it. +let res = assert.commandWorked(testDB.runCommand({ + aggregate: collectionName, + pipeline: [{$match: {_id: 1}}], + cursor: {}, + writeConcern: {w: "majority"} +})); +assert(res.cursor.firstBatch.length); +assert.eq(res.cursor.firstBatch[0], {_id: 1}); + +// An aggregation pipeline that writes will block on writeConcern. +assert.commandFailedWithCode(testDB.runCommand({ + aggregate: collectionName, + pipeline: [{$match: {_id: 1}}, {$out: collectionName + "_out"}], + cursor: {}, + writeConcern: {w: "majority", wtimeout: 1000} +}), + ErrorCodes.WriteConcernFailed); + +restartReplicationOnSecondaries(replTest); +replTest.awaitLastOpCommitted(); +replTest.stopSet(); })(); |