(
tests: CmapTest[],
options?: { testsToSkip?: SkipDescription[]; injectPoolStats?: boolean }
)
| 456 | }; |
| 457 | |
| 458 | export function runCmapTestSuite( |
| 459 | tests: CmapTest[], |
| 460 | options?: { testsToSkip?: SkipDescription[]; injectPoolStats?: boolean } |
| 461 | ) { |
| 462 | for (const test of tests) { |
| 463 | describe(test.name, function () { |
| 464 | let hostAddress: HostAddress, |
| 465 | server: Server, |
| 466 | threadContext: ThreadContext, |
| 467 | client: MongoClient; |
| 468 | |
| 469 | beforeEach(async function () { |
| 470 | let utilClient: MongoClient; |
| 471 | |
| 472 | const skipDescription = options?.testsToSkip?.find( |
| 473 | ({ description }) => description === test.description |
| 474 | ); |
| 475 | if (skipDescription) { |
| 476 | const alwaysSkip = skipDescription.skipIfCondition === 'always'; |
| 477 | const matchesLoadBalanceSkip = |
| 478 | skipDescription.skipIfCondition === 'loadBalanced' && this.configuration.isLoadBalanced; |
| 479 | |
| 480 | if (alwaysSkip || matchesLoadBalanceSkip) { |
| 481 | this.currentTest.skipReason = skipDescription.skipReason; |
| 482 | this.skip(); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if (this.configuration.isLoadBalanced) { |
| 487 | // The util client can always point at the single mongos LB frontend. |
| 488 | utilClient = this.configuration.newClient(this.configuration.singleMongosLoadBalancerUri); |
| 489 | } else { |
| 490 | utilClient = this.configuration.newClient(); |
| 491 | } |
| 492 | |
| 493 | await utilClient.connect(); |
| 494 | |
| 495 | const allRequirements = test.runOn || []; |
| 496 | |
| 497 | const someRequirementMet = |
| 498 | !allRequirements.length || |
| 499 | (await isAnyRequirementSatisfied(this.currentTest.ctx, allRequirements, utilClient)); |
| 500 | |
| 501 | if (!someRequirementMet) { |
| 502 | await utilClient.close(); |
| 503 | this.skip(); |
| 504 | // NOTE: the rest of the code below won't execute after the skip is invoked |
| 505 | } |
| 506 | |
| 507 | try { |
| 508 | const serverDescriptionMap = utilClient.topology?.s.description.servers; |
| 509 | const hosts = shuffle(serverDescriptionMap.keys()); |
| 510 | const selectedHostUri = hosts[0]; |
| 511 | hostAddress = serverDescriptionMap.get(selectedHostUri).hostAddress; |
| 512 | |
| 513 | const clientOptions: Pick<MongoClientOptions, 'appName'> = {}; |
| 514 | if (test.poolOptions?.appName) { |
| 515 | clientOptions.appName = test.poolOptions.appName; |
no test coverage detected