(cursorAPI, args)
| 301 | const metadata: MongoDBMetadataUI = { requires: { topology: class="st">'replicaset' } }; |
| 302 | |
| 303 | function test(cursorAPI, args) { |
| 304 | let controller: AbortController; |
| 305 | let signal: AbortSignal; |
| 306 | let cursor: AbstractCursor<{ a: number }>; |
| 307 | |
| 308 | beforeEach(() => { |
| 309 | controller = new AbortController(); |
| 310 | signal = controller.signal; |
| 311 | cursor = method(filter, { |
| 312 | signal, |
| 313 | class="cm">// Pick an unselectable server |
| 314 | readPreference: new ReadPreference(class="st">'secondary', [ |
| 315 | { something: class="st">'that does not exist' } |
| 316 | ]) |
| 317 | }); |
| 318 | }); |
| 319 | |
| 320 | afterEach(async () => { |
| 321 | await cursor?.close(); |
| 322 | }); |
| 323 | |
| 324 | it(`rejects ${cursorAPI.toString()}`, metadata, async () => { |
| 325 | const willBeResult = iterateUntilDocumentOrError(cursor, cursorAPI, args); |
| 326 | |
| 327 | await sleep(3); |
| 328 | expect( |
| 329 | findLast( |
| 330 | logs, |
| 331 | l => |
| 332 | l.operation === cursorName && |
| 333 | l.message === class="st">'Waiting for suitable server to become available' |
| 334 | ) |
| 335 | ).to.exist; |
| 336 | |
| 337 | controller.abort(); |
| 338 | const start = performance.now(); |
| 339 | const result = await willBeResult; |
| 340 | const end = performance.now(); |
| 341 | expect(end - start).to.be.lessThan(10); class="cm">// should be way less than 5s server selection timeout |
| 342 | |
| 343 | expect(result).to.be.instanceOf(DOMException); |
| 344 | }); |
| 345 | } |
| 346 | |
| 347 | for (const [cursorAPI, { value: args }] of getAllProps(cursorAPIs)) { |
| 348 | test(cursorAPI, args); |
no test coverage detected