|
2 | 2 |
|
3 | 3 | const { expect } = require('chai'); |
4 | 4 | const { loadSpecTests } = require('../../spec'); |
5 | | -const { parseRunOn } = require('../../tools/spec-runner'); |
| 5 | +const { legacyRunOnToRunOnRequirement } = require('../../tools/spec-runner'); |
| 6 | +const { topologySatisfies } = require('../../tools/unified-spec-runner/unified-utils'); |
6 | 7 |
|
7 | 8 | describe('Retryable Writes', function () { |
8 | 9 | let ctx = {}; |
9 | | - loadSpecTests('retryable-writes').forEach(suite => { |
10 | | - const environmentRequirementList = parseRunOn(suite.runOn); |
11 | | - environmentRequirementList.forEach(requires => { |
12 | | - const suiteName = `${suite.name} - ${requires.topology.join()}`; |
13 | | - |
14 | | - describe(suiteName, { |
15 | | - metadata: { requires }, |
16 | | - test: function () { |
17 | | - // Step 3: Test Teardown. Turn off failpoints, and close client |
18 | | - afterEach(function () { |
19 | | - if (!ctx.db || !ctx.client) { |
20 | | - return; |
21 | | - } |
| 10 | + const retryableWrites = loadSpecTests('retryable-writes'); |
| 11 | + |
| 12 | + for (const suite of retryableWrites) { |
| 13 | + describe(suite.name, function () { |
| 14 | + beforeEach(async function () { |
| 15 | + let utilClient; |
| 16 | + if (this.configuration.isLoadBalanced) { |
| 17 | + // The util client can always point at the single mongos LB frontend. |
| 18 | + utilClient = this.configuration.newClient(this.configuration.singleMongosLoadBalancerUri); |
| 19 | + } else { |
| 20 | + utilClient = this.configuration.newClient(); |
| 21 | + } |
22 | 22 |
|
23 | | - return Promise.resolve() |
24 | | - .then(() => |
25 | | - ctx.failPointName ? turnOffFailPoint(ctx.client, ctx.failPointName) : {} |
26 | | - ) |
27 | | - .then(() => ctx.client.close()) |
28 | | - .then(() => (ctx = {})); |
29 | | - }); |
| 23 | + await utilClient.connect(); |
30 | 24 |
|
31 | | - suite.tests.forEach(test => { |
32 | | - it(test.description, function () { |
33 | | - // Step 1: Test Setup. Includes a lot of boilerplate stuff |
34 | | - // like creating a client, dropping and refilling data collections, |
35 | | - // and enabling failpoints |
36 | | - return executeScenarioSetup(suite, test, this.configuration, ctx).then(() => |
37 | | - // Step 2: Run the test |
38 | | - executeScenarioTest(test, ctx) |
39 | | - ); |
40 | | - }); |
41 | | - }); |
| 25 | + const allRequirements = suite.runOn.map(legacyRunOnToRunOnRequirement); |
| 26 | + |
| 27 | + let shouldRun = true; |
| 28 | + for (const requirement of allRequirements) { |
| 29 | + shouldRun = |
| 30 | + shouldRun && (await topologySatisfies(this.currentTest.ctx, requirement, utilClient)); |
| 31 | + } |
| 32 | + |
| 33 | + await utilClient.close(); |
| 34 | + |
| 35 | + if (!shouldRun) this.skip(); |
| 36 | + }); |
| 37 | + |
| 38 | + afterEach(async function () { |
| 39 | + // Step 3: Test Teardown. Turn off failpoints, and close client |
| 40 | + if (!ctx.db || !ctx.client) { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + if (ctx.failPointName) { |
| 45 | + await turnOffFailPoint(ctx.client, ctx.failPointName); |
42 | 46 | } |
| 47 | + await ctx.client.close(); |
| 48 | + ctx = {}; // reset context |
43 | 49 | }); |
| 50 | + |
| 51 | + for (const test of suite.tests) { |
| 52 | + it(test.description, async function () { |
| 53 | + // Step 1: Test Setup. Includes a lot of boilerplate stuff |
| 54 | + // like creating a client, dropping and refilling data collections, |
| 55 | + // and enabling failpoints |
| 56 | + await executeScenarioSetup(suite, test, this.configuration, ctx); |
| 57 | + // Step 2: Run the test |
| 58 | + await executeScenarioTest(test, ctx); |
| 59 | + }); |
| 60 | + } |
44 | 61 | }); |
45 | | - }); |
| 62 | + } |
46 | 63 | }); |
47 | 64 |
|
48 | 65 | function executeScenarioSetup(scenario, test, config, ctx) { |
|
0 commit comments