Skip to content

Commit

Permalink
add non optimal parallelization across 6 instances (#815)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fuxingloh authored Nov 9, 2021
1 parent 742a106 commit 6bbdbb4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
preset: 'ts-jest',
testRegex: '((\\.|/)(e2e|test|spec))\\.[jt]sx?$',
testSequencer: require.resolve('./jest.sequencer'),
moduleNameMapper: {
'@defichain/jellyfish-(.*)': '<rootDir>/packages/jellyfish-$1/src',
'@defichain/testcontainers': '<rootDir>/packages/testcontainers/src',
Expand Down
19 changes: 19 additions & 0 deletions jest.sequencer.js
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6bbdbb4

Please sign in to comment.