Skip to content

Commit 3f65dd7

Browse files
committed
test(NODE-6858): add tests for ServerSelectionError
1 parent 14303bc commit 3f65dd7

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

test/integration/change-streams/change_stream.test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type CommandStartedEvent,
1515
type Db,
1616
isHello,
17+
LEGACY_HELLO_COMMAND,
1718
Long,
1819
MongoAPIError,
1920
MongoChangeStreamError,
@@ -2001,7 +2002,7 @@ describe('Change Streams', function () {
20012002
});
20022003
});
20032004

2004-
describe('ChangeStream resumability', function () {
2005+
describe.only('ChangeStream resumability', function () {
20052006
let client: MongoClient;
20062007
let collection: Collection;
20072008
let changeStream: ChangeStream;
@@ -2228,6 +2229,65 @@ describe('ChangeStream resumability', function () {
22282229
expect(changeStream.closed).to.be.true;
22292230
});
22302231
});
2232+
2233+
context.only('when the error is not a server error', function () {
2234+
let client1: MongoClient;
2235+
let client2: MongoClient;
2236+
2237+
beforeEach(async function () {
2238+
client1 = this.configuration.newClient(
2239+
{},
2240+
{ serverSelectionTimeoutMS: 1000, appName: 'client-errors' }
2241+
);
2242+
client2 = this.configuration.newClient();
2243+
2244+
collection = client1.db('client-errors').collection('test');
2245+
});
2246+
2247+
afterEach(async function () {
2248+
await client2.db('admin').command({
2249+
configureFailPoint: 'failCommand',
2250+
mode: 'off',
2251+
data: { appName: 'client-errors' }
2252+
} as FailCommandFailPoint);
2253+
2254+
await client1?.close();
2255+
await client2?.close();
2256+
});
2257+
2258+
it(
2259+
'should resume on ServerSelectionError',
2260+
{ requires: { topology: '!single' } },
2261+
async function () {
2262+
changeStream = collection.watch([]);
2263+
await initIteratorMode(changeStream);
2264+
2265+
await collection.insertOne({ a: 1 });
2266+
2267+
await client2.db('admin').command({
2268+
configureFailPoint: 'failCommand',
2269+
mode: 'alwaysOn',
2270+
data: {
2271+
failCommands: ['ping', 'hello', LEGACY_HELLO_COMMAND],
2272+
closeConnection: true,
2273+
handshakeCommands: true,
2274+
failInternalCommands: true,
2275+
appName: 'client-errors'
2276+
}
2277+
} as FailCommandFailPoint);
2278+
await client2
2279+
.db('admin')
2280+
.command({ replSetFreeze: 0 }, { readPreference: ReadPreference.secondary });
2281+
await client2
2282+
.db('admin')
2283+
.command({ replSetStepDown: 15, secondaryCatchUpPeriodSecs: 10, force: true });
2284+
// await sleep(15_000);
2285+
2286+
const change = await changeStream.next();
2287+
expect(change).to.containSubset({ operationType: 'insert', fullDocument: { a: 1 } });
2288+
}
2289+
);
2290+
});
22312291
});
22322292

22332293
context('#hasNext', function () {

0 commit comments

Comments
 (0)