Skip to content

Commit 716a6a0

Browse files
authoredJun 29, 2022
Merge pull request #65 from MatrixAI/feature-test-load-balancing
feat: test load balancing using jest's `--shard` option
2 parents 7c721e7 + 9bba1e4 commit 716a6a0

File tree

6 files changed

+2098
-1803
lines changed

6 files changed

+2098
-1803
lines changed
 

‎.gitlab-ci.yml

Lines changed: 41 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,36 @@ check:nix-dry:
7272
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
7373
when: manual
7474

75-
check:test:
75+
check:test-generate:
7676
stage: check
77-
needs: []
7877
script:
78+
- mkdir -p ./tmp
7979
- >
8080
nix-shell --run '
81-
npm run build --verbose;
82-
npm test -- --ci --coverage;
81+
./scripts/test-pipelines.sh > ./tmp/test-pipelines.yml
8382
'
8483
artifacts:
8584
when: always
86-
reports:
87-
junit:
88-
- ./tmp/junit/junit.xml
89-
coverage_report:
90-
coverage_format: cobertura
91-
path: ./tmp/coverage/cobertura-coverage.xml
92-
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
85+
paths:
86+
- ./tmp/test-pipelines.yml
87+
rules:
88+
# Runs on staging commits and ignores version commits
89+
- if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
90+
# Manually run on commits other than master and staging and ignore version commits
91+
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
92+
when: manual
93+
94+
check:test:
95+
stage: check
96+
needs:
97+
- check:test-generate
98+
inherit:
99+
variables: false
100+
trigger:
101+
include:
102+
- artifact: tmp/test-pipelines.yml
103+
job: check:test-generate
104+
strategy: depend
93105
rules:
94106
# Runs on staging commits and ignores version commits
95107
- if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -125,82 +137,35 @@ build:merge:
125137
# Runs on tag pipeline where the tag is a prerelease or release version
126138
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
127139

128-
build:linux:
140+
build:build-generate:
129141
stage: build
130-
needs: []
131142
script:
143+
- mkdir -p ./tmp
132144
- >
133145
nix-shell --run '
134-
npm run build --verbose;
135-
npm test -- --ci --coverage;
146+
./scripts/build-pipelines.sh > ./tmp/build-pipelines.yml
136147
'
137148
artifacts:
138149
when: always
139-
reports:
140-
junit:
141-
- ./tmp/junit/junit.xml
142-
coverage_report:
143-
coverage_format: cobertura
144-
path: ./tmp/coverage/cobertura-coverage.xml
145150
paths:
146-
# Only the build:linux preserves the dist
147-
- ./dist
148-
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
149-
rules:
150-
# Runs on staging commits and ignores version commits
151-
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
152-
# Runs on tag pipeline where the tag is a prerelease or release version
153-
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
154-
155-
build:windows:
156-
stage: build
157-
needs: []
158-
tags:
159-
- windows
160-
before_script:
161-
- choco install nodejs --version=16.14.2 -y
162-
- refreshenv
163-
script:
164-
- npm config set msvs_version 2019
165-
- npm install --ignore-scripts
166-
- $env:Path = "$(npm bin);" + $env:Path
167-
- npm run build --verbose
168-
- npm test -- --ci
169-
artifacts:
170-
when: always
171-
reports:
172-
junit:
173-
- ./tmp/junit/junit.xml
151+
- ./tmp/build-pipelines.yml
174152
rules:
175153
# Runs on staging commits and ignores version commits
176154
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
177155
# Runs on tag pipeline where the tag is a prerelease or release version
178156
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
179157

180-
build:macos:
158+
build:platforms:
181159
stage: build
182-
needs: []
183-
tags:
184-
- shared-macos-amd64
185-
image: macos-11-xcode-12
186-
variables:
187-
HOMEBREW_NO_INSTALL_UPGRADE: "true"
188-
HOMEBREW_NO_INSTALL_CLEANUP: "true"
189-
before_script:
190-
- eval "$(brew shellenv)"
191-
- brew install node@16
192-
- brew link --overwrite node@16
193-
- hash -r
194-
script:
195-
- npm install --ignore-scripts
196-
- export PATH="$(npm bin):$PATH"
197-
- npm run build --verbose
198-
- npm test -- --ci
199-
artifacts:
200-
when: always
201-
reports:
202-
junit:
203-
- ./tmp/junit/junit.xml
160+
needs:
161+
- build:build-generate
162+
inherit:
163+
variables: false
164+
trigger:
165+
include:
166+
- artifact: tmp/build-pipelines.yml
167+
job: build:build-generate
168+
strategy: depend
204169
rules:
205170
# Runs on staging commits and ignores version commits
206171
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -210,9 +175,7 @@ build:macos:
210175
build:prerelease:
211176
stage: build
212177
needs:
213-
- build:linux
214-
- build:windows
215-
- build:macos
178+
- build:platforms
216179
# Don't interrupt publishing job
217180
interruptible: false
218181
before_script:
@@ -235,9 +198,7 @@ build:prerelease:
235198
integration:builds:
236199
stage: integration
237200
needs:
238-
- build:linux
239-
- build:windows
240-
- build:macos
201+
- build:platforms
241202
script:
242203
- mkdir -p ./builds
243204
- >
@@ -434,11 +395,7 @@ integration:merge:
434395
stage: integration
435396
needs:
436397
- build:merge
437-
- job: build:linux
438-
optional: true
439-
- job: build:windows
440-
optional: true
441-
- job: build:macos
398+
- job: build:platforms
442399
optional: true
443400
- job: integration:nix
444401
optional: true
@@ -514,9 +471,7 @@ release:deployment:tag:
514471
release:distribution:
515472
stage: release
516473
needs:
517-
- build:linux
518-
- build:windows
519-
- build:macos
474+
- build:platforms
520475
- integration:builds
521476
- integration:merge
522477
- release:deployment:tag

‎jest.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ module.exports = {
3838
},
3939
reporters: [
4040
'default',
41-
['jest-junit', { outputDirectory: '<rootDir>/tmp/junit' }],
41+
['jest-junit', {
42+
outputDirectory: '<rootDir>/tmp/junit',
43+
classNameTemplate: '{classname}',
44+
titleTemplate: '{title}',
45+
addFileAttribute: 'true',
46+
}],
4247
],
4348
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}', '!src/**/*.d.ts'],
4449
coverageReporters: ['text', 'cobertura'],

‎package-lock.json

Lines changed: 1828 additions & 1713 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@
4949
"eslint-config-prettier": "^8.5.0",
5050
"eslint-plugin-import": "^2.26.0",
5151
"eslint-plugin-prettier": "^4.0.0",
52-
"jest": "^27.2.5",
53-
"jest-junit": "^13.2.0",
52+
"jest": "^28.1.1",
53+
"jest-junit": "^14.0.0",
5454
"jest-mock-process": "^1.4.0",
5555
"pkg": "5.6.0",
5656
"prettier": "^2.6.2",
5757
"rimraf": "^3.0.2",
58-
"ts-jest": "^27.0.5",
58+
"ts-jest": "^28.0.5",
5959
"ts-node": "^10.4.0",
6060
"tsconfig-paths": "^3.9.0",
6161
"typedoc": "^0.22.15",

‎scripts/build-pipelines.sh

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env bash
2+
3+
shopt -s globstar
4+
shopt -s nullglob
5+
6+
# Quote the heredoc to prevent shell expansion
7+
cat << "EOF"
8+
workflow:
9+
rules:
10+
# Disable merge request pipelines
11+
- if: $CI_MERGE_REQUEST_ID
12+
when: never
13+
- when: always
14+
default:
15+
interruptible: true
16+
variables:
17+
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
18+
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
19+
GIT_SUBMODULE_STRATEGY: "recursive"
20+
# Cache .npm
21+
NPM_CONFIG_CACHE: "./tmp/npm"
22+
# Prefer offline node module installation
23+
NPM_CONFIG_PREFER_OFFLINE: "true"
24+
# `ts-node` has its own cache
25+
# It must use an absolute path, otherwise ts-node calls will CWD
26+
TS_CACHED_TRANSPILE_CACHE: "${CI_PROJECT_DIR}/tmp/ts-node-cache"
27+
TS_CACHED_TRANSPILE_PORTABLE: "true"
28+
# Homebrew cache only used by macos runner
29+
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"
30+
# Cached directories shared between jobs & pipelines per-branch per-runner
31+
cache:
32+
key: $CI_COMMIT_REF_SLUG
33+
paths:
34+
- ./tmp/npm/
35+
- ./tmp/ts-node-cache/
36+
# Homebrew cache is only used by the macos runner
37+
- ./tmp/Homebrew
38+
# `jest` cache is configured in jest.config.js
39+
- ./tmp/jest/
40+
stages:
41+
- build # Cross-platform library compilation, unit tests
42+
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
43+
EOF
44+
45+
printf "\n"
46+
47+
# Using shards to optimise tests
48+
# In the future we can incorporate test durations rather than using
49+
# a static value for the parallel keyword
50+
51+
cat << "EOF"
52+
build:linux:
53+
stage: build
54+
needs: []
55+
parallel: 2
56+
script:
57+
- >
58+
nix-shell --run '
59+
npm run build --verbose;
60+
npm test -- --ci --runInBand --coverage --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL;
61+
'
62+
artifacts:
63+
when: always
64+
reports:
65+
junit:
66+
- ./tmp/junit/junit.xml
67+
coverage_report:
68+
coverage_format: cobertura
69+
path: ./tmp/coverage/cobertura-coverage.xml
70+
paths:
71+
# Only the build:linux preserves the dist
72+
- ./dist
73+
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
74+
rules:
75+
# Runs on staging commits and ignores version commits
76+
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
77+
# Runs on tag pipeline where the tag is a prerelease or release version
78+
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
79+
EOF
80+
81+
printf "\n"
82+
83+
cat << "EOF"
84+
build:windows:
85+
stage: build
86+
needs: []
87+
parallel: 2
88+
tags:
89+
- windows
90+
before_script:
91+
- choco install nodejs --version=16.14.2 -y
92+
- refreshenv
93+
script:
94+
- npm config set msvs_version 2019
95+
- npm install --ignore-scripts
96+
- $env:Path = "$(npm bin);" + $env:Path
97+
- npm run build --verbose
98+
- npm test -- --ci --runInBand --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
99+
artifacts:
100+
when: always
101+
reports:
102+
junit:
103+
- ./tmp/junit/junit.xml
104+
rules:
105+
# Runs on staging commits and ignores version commits
106+
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
107+
# Runs on tag pipeline where the tag is a prerelease or release version
108+
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
109+
EOF
110+
111+
printf "\n"
112+
113+
cat << "EOF"
114+
build:macos:
115+
stage: build
116+
needs: []
117+
parallel: 2
118+
tags:
119+
- shared-macos-amd64
120+
image: macos-11-xcode-12
121+
variables:
122+
HOMEBREW_NO_INSTALL_UPGRADE: "true"
123+
HOMEBREW_NO_INSTALL_CLEANUP: "true"
124+
before_script:
125+
- eval "$(brew shellenv)"
126+
- brew install node@16
127+
- brew link --overwrite node@16
128+
- hash -r
129+
script:
130+
- npm install --ignore-scripts
131+
- export PATH="$(npm bin):$PATH"
132+
- npm run build --verbose
133+
- npm test -- --ci --runInBand --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
134+
artifacts:
135+
when: always
136+
reports:
137+
junit:
138+
- ./tmp/junit/junit.xml
139+
rules:
140+
# Runs on staging commits and ignores version commits
141+
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
142+
# Runs on tag pipeline where the tag is a prerelease or release version
143+
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
144+
EOF
145+
146+
printf "\n"

‎scripts/test-pipelines.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
shopt -s globstar
4+
shopt -s nullglob
5+
6+
# Quote the heredoc to prevent shell expansion
7+
cat << "EOF"
8+
workflow:
9+
rules:
10+
# Disable merge request pipelines
11+
- if: $CI_MERGE_REQUEST_ID
12+
when: never
13+
- when: always
14+
default:
15+
interruptible: true
16+
variables:
17+
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
18+
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
19+
GIT_SUBMODULE_STRATEGY: "recursive"
20+
# Cache .npm
21+
NPM_CONFIG_CACHE: "./tmp/npm"
22+
# Prefer offline node module installation
23+
NPM_CONFIG_PREFER_OFFLINE: "true"
24+
# `ts-node` has its own cache
25+
# It must use an absolute path, otherwise ts-node calls will CWD
26+
TS_CACHED_TRANSPILE_CACHE: "${CI_PROJECT_DIR}/tmp/ts-node-cache"
27+
TS_CACHED_TRANSPILE_PORTABLE: "true"
28+
# Cached directories shared between jobs & pipelines per-branch per-runner
29+
cache:
30+
key: $CI_COMMIT_REF_SLUG
31+
paths:
32+
- ./tmp/npm/
33+
- ./tmp/ts-node-cache/
34+
# `jest` cache is configured in jest.config.js
35+
- ./tmp/jest/
36+
stages:
37+
- check # Linting, unit tests
38+
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
39+
EOF
40+
41+
printf "\n"
42+
43+
# Using shards to optimise tests
44+
# In the future we can incorporate test durations rather than using
45+
# a static value for the parallel keyword
46+
cat << "EOF"
47+
check:test:
48+
stage: check
49+
needs: []
50+
parallel: 2
51+
script:
52+
- >
53+
nix-shell --run '
54+
npm run build --verbose;
55+
npm test -- --ci --runInBand --coverage --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL;
56+
'
57+
artifacts:
58+
when: always
59+
reports:
60+
junit:
61+
- ./tmp/junit/junit.xml
62+
coverage_report:
63+
coverage_format: cobertura
64+
path: ./tmp/coverage/cobertura-coverage.xml
65+
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
66+
rules:
67+
# Runs on staging commits and ignores version commits
68+
- if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
69+
# Manually run on commits other than master and staging and ignore version commits
70+
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
71+
when: manual
72+
EOF
73+
74+
printf "\n"

0 commit comments

Comments
 (0)
Please sign in to comment.