|
2 | 2 | import { type TestConfiguration } from '../../tools/runner/config'; |
3 | 3 | import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder'; |
4 | 4 |
|
5 | | -describe.skip('MongoClient.close() Integration', () => { |
| 5 | +describe('MongoClient.close() Integration', () => { |
6 | 6 | // note: these tests are set-up in accordance of the resource ownership tree |
7 | 7 |
|
8 | 8 | let config: TestConfiguration; |
@@ -75,44 +75,29 @@ describe.skip('MongoClient.close() Integration', () => { |
75 | 75 | describe('Topology', () => { |
76 | 76 | describe('Node.js resource: Server Selection Timer', () => { |
77 | 77 | describe('after a Topology is created through client.connect()', () => { |
78 | | - it('server selection timers are cleaned up by client.close()', async () => { |
79 | | - const run = async function ({ |
80 | | - MongoClient, |
81 | | - uri, |
82 | | - expect, |
83 | | - sinon, |
84 | | - sleep, |
85 | | - mongodb, |
86 | | - getTimerCount, |
87 | | - timers |
88 | | - }) { |
| 78 | + const metadata: MongoDBMetadataUI = { requires: { topology: 'replicaset' } }; |
| 79 | + |
| 80 | + it('server selection timers are cleaned up by client.close()', metadata, async () => { |
| 81 | + const run = async function ({ MongoClient, uri, expect, sleep, mongodb, getTimerCount }) { |
89 | 82 | const serverSelectionTimeoutMS = 2222; |
90 | | - const client = new MongoClient(uri, { minPoolSize: 1, serverSelectionTimeoutMS }); |
91 | | - const timeoutStartedSpy = sinon.spy(timers, 'setTimeout'); |
92 | | - let serverSelectionTimeoutStarted = false; |
93 | | - |
94 | | - // make server selection hang so check out timer isn't cleared and check that the timeout has started |
95 | | - sinon.stub(Promise, 'race').callsFake(async ([_serverPromise, timeout]) => { |
96 | | - serverSelectionTimeoutStarted = |
97 | | - timeoutStartedSpy |
98 | | - .getCalls() |
99 | | - .filter(r => r.args.includes(serverSelectionTimeoutMS)) |
100 | | - .flat().length > 0; |
101 | | - await timeout; |
| 83 | + const client = new MongoClient(uri, { |
| 84 | + minPoolSize: 1, |
| 85 | + serverSelectionTimeoutMS, |
| 86 | + readPreference: new mongodb.ReadPreference('secondary', [ |
| 87 | + { something: 'that does not exist' } |
| 88 | + ]) |
102 | 89 | }); |
103 | | - |
104 | 90 | const insertPromise = client.db('db').collection('collection').insertOne({ x: 1 }); |
105 | 91 |
|
106 | 92 | // don't allow entire server selection timer to elapse to ensure close is called mid-timeout |
107 | 93 | await sleep(serverSelectionTimeoutMS / 2); |
108 | | - expect(serverSelectionTimeoutStarted).to.be.true; |
109 | 94 |
|
110 | 95 | expect(getTimerCount()).to.not.equal(0); |
111 | 96 | await client.close(); |
112 | 97 | expect(getTimerCount()).to.equal(0); |
113 | 98 |
|
114 | 99 | const err = await insertPromise.catch(e => e); |
115 | | - expect(err).to.be.instanceOf(mongodb.MongoServerSelectionError); |
| 100 | + expect(err).to.be.instanceOf(mongodb.MongoTopologyClosedError); |
116 | 101 | }; |
117 | 102 | await runScriptAndGetProcessInfo('timer-server-selection', config, run); |
118 | 103 | }); |
|
0 commit comments