From 6bbdbb48d3fa225cf8bdd678081a64086e984b06 Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Tue, 9 Nov 2021 13:59:01 +0800 Subject: [PATCH] add non optimal parallelization across 6 instances (#815) * add non optimal parallelization across 6 instances * randomize sequencer with deterministic ordering disable fail-fast to allow more explicit failure reporting * fixed tests sorting code ordering --- .github/workflows/ci.yml | 8 +++++++ jest.config.js | 1 + jest.sequencer.js | 19 ++++++++++++++++ package-lock.json | 47 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 76 insertions(+) create mode 100644 jest.sequencer.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17cf1667bf..91d7ead9ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,12 @@ jobs: test: name: Test runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + instance: [ 0, 1, 2, 3, 4, 5] + env: + GH_INSTANCE_TOTAL: 6 steps: - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 - uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c @@ -36,6 +42,8 @@ jobs: - run: npm ci - run: npm run test:ci + env: + GH_INSTANCE_INDEX: ${{ matrix.instance }} - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b with: diff --git a/jest.config.js b/jest.config.js index 5ee4be5251..0b09ac3653 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,7 @@ module.exports = { preset: 'ts-jest', testRegex: '((\\.|/)(e2e|test|spec))\\.[jt]sx?$', + testSequencer: require.resolve('./jest.sequencer'), moduleNameMapper: { '@defichain/jellyfish-(.*)': '/packages/jellyfish-$1/src', '@defichain/testcontainers': '/packages/testcontainers/src', diff --git a/jest.sequencer.js b/jest.sequencer.js new file mode 100644 index 0000000000..fd929a8677 --- /dev/null +++ b/jest.sequencer.js @@ -0,0 +1,19 @@ +const Sequencer = require('@jest/test-sequencer').default +const ShuffleSeed = require('shuffle-seed') + +class CustomSequencer extends Sequencer { + sort (tests) { + // In CI, GitHub Actions tests are parallelized across multiple instance + if (process.env.GH_INSTANCE_TOTAL) { + const total = parseInt(process.env.GH_INSTANCE_TOTAL, 10) + const index = parseInt(process.env.GH_INSTANCE_INDEX, 10) + + return ShuffleSeed.shuffle(tests, 'deterministic') + .filter((_, i) => i % total === index) + } + + return tests + } +} + +module.exports = CustomSequencer diff --git a/package-lock.json b/package-lock.json index fc86b6d44b..dfec94a280 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "jest": "^27.3.1", "lerna": "^4.0.0", "lint-staged": "^11.2.6", + "shuffle-seed": "^1.1.6", "ts-jest": "^27.0.7", "typescript": "4.2.4", "wait-for-expect": "^3.0.2" @@ -10395,6 +10396,12 @@ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, + "node_modules/seedrandom": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.4.tgz", + "integrity": "sha512-9A+PDmgm+2du77B5i0Ip2cxOqqHjgNxnBgglxLcX78A2D6c2rTo61z4jnVABpF4cKeDMDG+cmXXvdnqse2VqMA==", + "dev": true + }, "node_modules/semver": { "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", @@ -10478,6 +10485,15 @@ "node": ">=4" } }, + "node_modules/shuffle-seed": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/shuffle-seed/-/shuffle-seed-1.1.6.tgz", + "integrity": "sha1-UzwSaDurO0+j6HUfxOViFGdEJgs=", + "dev": true, + "dependencies": { + "seedrandom": "^2.4.2" + } + }, "node_modules/side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -15544,6 +15560,7 @@ "jest": "^27.3.1", "lerna": "^4.0.0", "lint-staged": "^11.2.6", + "shuffle-seed": "*", "ts-jest": "^27.0.7", "typescript": "4.2.4", "wait-for-expect": "^3.0.2" @@ -23109,6 +23126,12 @@ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, + "seedrandom": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.4.tgz", + "integrity": "sha512-9A+PDmgm+2du77B5i0Ip2cxOqqHjgNxnBgglxLcX78A2D6c2rTo61z4jnVABpF4cKeDMDG+cmXXvdnqse2VqMA==", + "dev": true + }, "semver": { "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", @@ -23162,6 +23185,15 @@ "rechoir": "^0.6.2" } }, + "shuffle-seed": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/shuffle-seed/-/shuffle-seed-1.1.6.tgz", + "integrity": "sha1-UzwSaDurO0+j6HUfxOViFGdEJgs=", + "dev": true, + "requires": { + "seedrandom": "^2.4.2" + } + }, "side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -28585,6 +28617,12 @@ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, + "seedrandom": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.4.tgz", + "integrity": "sha512-9A+PDmgm+2du77B5i0Ip2cxOqqHjgNxnBgglxLcX78A2D6c2rTo61z4jnVABpF4cKeDMDG+cmXXvdnqse2VqMA==", + "dev": true + }, "semver": { "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", @@ -28638,6 +28676,15 @@ "rechoir": "^0.6.2" } }, + "shuffle-seed": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/shuffle-seed/-/shuffle-seed-1.1.6.tgz", + "integrity": "sha1-UzwSaDurO0+j6HUfxOViFGdEJgs=", + "dev": true, + "requires": { + "seedrandom": "^2.4.2" + } + }, "side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", diff --git a/package.json b/package.json index 1030e47589..3b29c51892 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "jest": "^27.3.1", "lerna": "^4.0.0", "lint-staged": "^11.2.6", + "shuffle-seed": "^1.1.6", "ts-jest": "^27.0.7", "typescript": "4.2.4", "wait-for-expect": "^3.0.2"