({
MongoClient,
uri,
expect,
sleep,
mongodb,
getTimerCount
})
| 89 | metadata, |
| 90 | async function () { |
| 91 | const run = async function ({ |
| 92 | MongoClient, |
| 93 | uri, |
| 94 | expect, |
| 95 | sleep, |
| 96 | mongodb, |
| 97 | getTimerCount |
| 98 | }) { |
| 99 | const serverSelectionTimeoutMS = 2222; |
| 100 | const client = new MongoClient(uri, { |
| 101 | minPoolSize: 1, |
| 102 | serverSelectionTimeoutMS, |
| 103 | readPreference: new mongodb.ReadPreference('secondary', [ |
| 104 | { something: 'that does not exist' } |
| 105 | ]) |
| 106 | }); |
| 107 | const insertPromise = client.db('db').collection('collection').insertOne({ x: 1 }); |
| 108 | |
| 109 | // don't allow entire server selection timer to elapse to ensure close is called mid-timeout |
| 110 | await sleep(serverSelectionTimeoutMS / 2); |
| 111 | |
| 112 | expect(getTimerCount()).to.not.equal(0); |
| 113 | await client.close(); |
| 114 | expect(getTimerCount()).to.equal(0); |
| 115 | |
| 116 | const err = await insertPromise.catch(e => e); |
| 117 | expect(err).to.be.instanceOf(mongodb.MongoTopologyClosedError); |
| 118 | }; |
| 119 | await runScriptAndGetProcessInfo('timer-server-selection', this.configuration, run); |
| 120 | } |
| 121 | ); |
nothing calls this directly
no test coverage detected