(function() {
|
"use strict";
|
|
var st = new ShardingTest({
|
shards: 2,
|
rs: {nodes: 2, setParameter: {periodicNoopIntervalSecs: 1, writePeriodicNoops: true}}
|
});
|
|
var testDB = st.s.getDB('test');
|
testDB.dropDatabase();
|
|
assert.commandWorked(testDB.adminCommand({enableSharding: 'test'}));
|
st.ensurePrimaryShard('test', st.shard0.shardName);
|
st.shardColl(testDB.foo, {x: 1}, {x: 10}, {x: 10});
|
|
let stream = testDB.foo.aggregate([{$changeStream: {}}], {$readPreference: {mode: "secondary"}});
|
assert.writeOK(testDB.foo.insert({x: 0}, {writeConcern: {w: "majority"}}));
|
|
// This will trigger a refresh on the secondaries and they will now be aware that the collection
|
// is sharded.
|
assert.commandWorked(testDB.foo.runCommand({
|
count: "foo",
|
query: {},
|
$readPreference: {mode: "secondary"},
|
readConcern: {"level": "local"}
|
}));
|
|
assert.soon(()=> stream.hasNext());
|
|
let token = stream.next()._id;
|
|
// Restart the secondary, resetting it's sharding state to be unsharded.
|
st.rs0.restart(st.rs0.getSecondary());
|
|
let resumeStream = testDB.foo.aggregate([{$changeStream: {resumeAfter: token}}],
|
{$readPreference: {mode: "secondary"}});
|
|
assert.writeOK(testDB.foo.insert({x: 1})); // THIS WILL FAIL TO RESUME
|
assert.soon(()=> resumeStream.hasNext());
|
|
st.stop();
|
}());
|