(test: CmapTest, threadContext: ThreadContext)
| 364 | } |
| 365 | |
| 366 | async function runCmapTest(test: CmapTest, threadContext: ThreadContext) { |
| 367 | expect(CMAP_TEST_KEYS).to.include.members(Object.keys(test)); |
| 368 | |
| 369 | const poolOptions = test.poolOptions || {}; |
| 370 | expect(CMAP_POOL_OPTION_NAMES).to.include.members(Object.keys(poolOptions)); |
| 371 | |
| 372 | let minPoolSizeCheckFrequencyMS; |
| 373 | if (poolOptions.backgroundThreadIntervalMS) { |
| 374 | if (poolOptions.backgroundThreadIntervalMS !== -1) { |
| 375 | minPoolSizeCheckFrequencyMS = poolOptions.backgroundThreadIntervalMS; |
| 376 | } |
| 377 | delete poolOptions.backgroundThreadIntervalMS; |
| 378 | } |
| 379 | |
| 380 | delete poolOptions.appName; |
| 381 | |
| 382 | const operations = test.operations; |
| 383 | const expectedError = test.error; |
| 384 | const expectedEvents = test.events; |
| 385 | const ignoreEvents = test.ignore || []; |
| 386 | |
| 387 | const MAIN_THREAD_KEY = Symbol('Main Thread'); |
| 388 | const mainThread = threadContext.getThread(MAIN_THREAD_KEY); |
| 389 | mainThread.start(); |
| 390 | |
| 391 | threadContext.createPool({ |
| 392 | ...poolOptions, |
| 393 | minPoolSizeCheckFrequencyMS |
| 394 | }); |
| 395 | // yield control back to the event loop so that the ConnectionPoolCreatedEvent |
| 396 | // has a chance to be fired before any synchronously-emitted events from |
| 397 | // the queued operations |
| 398 | await sleep(); |
| 399 | |
| 400 | for (const idx in operations) { |
| 401 | const op = operations[idx]; |
| 402 | |
| 403 | const threadKey = op.name === 'checkOut' ? op.thread || MAIN_THREAD_KEY : MAIN_THREAD_KEY; |
| 404 | if (threadKey === MAIN_THREAD_KEY) { |
| 405 | mainThread.queue(op); |
| 406 | } else { |
| 407 | const thread = threadContext.getThread(threadKey); |
| 408 | mainThread.queue(op, thread); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | const actualError = await mainThread.finish().catch(e => e); |
| 413 | |
| 414 | if (expectedError) { |
| 415 | expect(actualError).to.exist; |
| 416 | const { type: errorType, message: errorMessage, ...errorPropsToCheck } = expectedError; |
| 417 | expect( |
| 418 | actualError, |
| 419 | `${actualError.name} does not match "Mongo${errorType}", ${actualError.message} ${actualError.stack}` |
| 420 | ).to.have.property('name', `Mongo${errorType}`); |
| 421 | if (errorMessage) { |
| 422 | if ( |
| 423 | errorMessage === 'Timed out while checking out a connection from connection pool' && |
no test coverage detected