Skip to content

Commit c4495ea

Browse files
authored
Parallel tests (#2968)
1 parent 4b680da commit c4495ea

File tree

7 files changed

+267
-138
lines changed

7 files changed

+267
-138
lines changed

azure-pipelines.yml

Lines changed: 51 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,41 @@ variables:
66
CI: true
77

88
jobs:
9-
- job: Tests
9+
- job: Test
10+
pool:
11+
name: 'Default'
12+
13+
workspace:
14+
clean: resources
15+
16+
strategy:
17+
parallel: 4
18+
19+
steps:
20+
- powershell: echo "IP for RDP connections:" $(Invoke-RestMethod ipinfo.io/ip)
21+
displayName: 'Get RDP address'
22+
23+
- powershell: Set-DisplayResolution -Width 1920 -Height 1080 -Force
24+
displayName: 'Setup Screen Resolution'
25+
26+
- script: yarn install --frozen-lockfile --check-files 2>&1
27+
displayName: 'Install Dependencies'
28+
29+
- script: node node_modules/electron/install.js
30+
displayName: 'Install Electron'
31+
32+
- script: 'yarn ci:compile'
33+
displayName: 'Compile Assets'
34+
35+
- script: 'yarn ci:tests'
36+
displayName: 'Run Tests'
37+
env:
38+
SLOBS_TEST_USER_POOL_TOKEN: $(userPoolToken)
39+
BROWSER_SOURCE_HARDWARE_ACCELERATION: 'OFF'
40+
SLOBS_TEST_STREAM_KEY: $(twitchStreamKey)
41+
SLOBS_TEST_RUN_CHUNK: "$(System.JobPositionInPhase)/$(System.TotalJobsInPhase)"
42+
43+
- job: Check_eslint_and_strict_nulls_regression
1044

1145
pool:
1246
name: 'Default'
@@ -25,26 +59,13 @@ jobs:
2559
- script: yarn install --frozen-lockfile --check-files 2>&1
2660
displayName: 'Install Dependencies'
2761

28-
- script: node node_modules/electron/install.js
29-
displayName: 'Install Electron'
30-
3162
- script: 'yarn eslint'
3263
displayName: 'ESLint'
3364

3465
- script: 'yarn compile:strictnulls'
3566
displayName: 'Check regressions in files with strictNullChecks'
3667

37-
- script: 'yarn ci:compile'
38-
displayName: 'Compile Assets'
39-
40-
- script: 'yarn ci:tests'
41-
displayName: 'Run Tests'
42-
env:
43-
SLOBS_TEST_USER_POOL_TOKEN: $(userPoolToken)
44-
BROWSER_SOURCE_HARDWARE_ACCELERATION: 'OFF'
45-
SLOBS_TEST_STREAM_KEY: $(twitchStreamKey)
46-
47-
# - job: Screenshots
68+
# - job: Performance
4869
#
4970
# pool:
5071
# name: 'Default'
@@ -54,64 +75,26 @@ jobs:
5475
#
5576
# steps:
5677
#
57-
# - powershell: echo "IP for RDP connections:" $(Invoke-RestMethod ipinfo.io/ip)
58-
# displayName: 'Get RDP address'
59-
#
60-
# - powershell: Set-DisplayResolution -Width 1920 -Height 1080 -Force
61-
# displayName: 'Setup Screen Resolution'
78+
# - powershell: echo "IP for RDP connections:" $(Invoke-RestMethod ipinfo.io/ip)
79+
# displayName: 'Get RDP address'
6280
#
63-
# - script: yarn install --frozen-lockfile --check-files 2>&1
64-
# displayName: 'Install Dependencies'
81+
# - powershell: Set-DisplayResolution -Width 1920 -Height 1080 -Force
82+
# displayName: 'Setup Screen Resolution'
6583
#
66-
# - script: node node_modules/electron/install.js
67-
# displayName: 'Install Electron'
84+
# - script: yarn install --frozen-lockfile --check-files 2>&1
85+
# displayName: 'Install Dependencies'
6886
#
69-
# - script: 'yarn ci:screentests'
70-
# displayName: 'Snapshot testing'
71-
# env:
72-
# BROWSER_SOURCE_HARDWARE_ACCELERATION: 'OFF'
73-
# SLOBS_TEST_USER_POOL_TOKEN: $(userPoolToken)
74-
# STREAMLABS_BOT_ID: $(streamlabsBotId)
75-
# STREAMLABS_BOT_KEY: $(streamlabsBotKey)
76-
# AWS_BUCKET: $(awsBucket)
77-
# AWS_ACCESS_KEY: $(awsAccessKey)
78-
# AWS_SECRET_KEY: $(awsSecretKey)
87+
# - script: node node_modules/electron/install.js
88+
# displayName: 'Install Electron'
7989
#
80-
# - task: PublishPipelineArtifact@0
81-
# inputs:
82-
# artifactName: 'SnapshotsResults'
83-
# targetPath: $(Build.SourcesDirectory)/test-dist/screentest
90+
# - script: 'yarn ci:compile'
91+
# displayName: 'Compile Assets'
8492
#
85-
- job: Performance
86-
87-
pool:
88-
name: 'Default'
89-
90-
workspace:
91-
clean: resources
92-
93-
steps:
94-
95-
- powershell: echo "IP for RDP connections:" $(Invoke-RestMethod ipinfo.io/ip)
96-
displayName: 'Get RDP address'
97-
98-
- powershell: Set-DisplayResolution -Width 1920 -Height 1080 -Force
99-
displayName: 'Setup Screen Resolution'
100-
101-
- script: yarn install --frozen-lockfile --check-files 2>&1
102-
displayName: 'Install Dependencies'
103-
104-
- script: node node_modules/electron/install.js
105-
displayName: 'Install Electron'
106-
107-
- script: 'yarn ci:compile'
108-
displayName: 'Compile Assets'
109-
110-
- script: 'yarn ci:performance'
111-
displayName: 'Performance testing'
112-
env:
113-
BROWSER_SOURCE_HARDWARE_ACCELERATION: 'OFF'
114-
SLOBS_TEST_USER_POOL_TOKEN: $(userPoolToken)
93+
# - script: 'yarn ci:performance'
94+
# displayName: 'Performance testing'
95+
# env:
96+
# BROWSER_SOURCE_HARDWARE_ACCELERATION: 'OFF'
97+
# SLOBS_TEST_USER_POOL_TOKEN: $(userPoolToken)
11598

11699
- job: macOS
117100

test-job-template.yml

Whitespace-only changes.

test/helpers/runner.js

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Tests runner script:
3+
* - fetch average test timings from the DB
34
* - run tests
45
* - if some tests failed retry only these tests
56
*/
@@ -8,33 +9,37 @@ const { execSync } = require('child_process');
89
const fs = require('fs');
910
const rimraf = require('rimraf');
1011
const request = require('request');
12+
const fetch = require('node-fetch');
1113

1214
const failedTestsFile = 'test-dist/failed-tests.json';
1315
const args = process.argv.slice(2);
1416
const TIMEOUT = 3; // timeout in minutes
1517

16-
(function main() {
18+
(async function main() {
1719
try {
1820
rimraf.sync(failedTestsFile);
21+
await createTestTimingsFile();
1922
execSync(`yarn test --timeout=${TIMEOUT}m ` + args.join(' '), { stdio: [0, 1, 2] });
2023
} catch (e) {
24+
console.log(e);
2125
retryTests();
2226
}
2327
})();
2428

25-
2629
function retryTests() {
2730
log('retrying failed tests');
2831

2932
if (!fs.existsSync(failedTestsFile)) {
3033
throw 'no tests to retry';
3134
}
3235

33-
const failedTests = JSON.parse(fs.readFileSync(failedTestsFile));
36+
const failedTests = JSON.parse(fs.readFileSync(failedTestsFile, 'utf8'));
3437
const retryingArgs = failedTests.map(testName => `--match="${testName}"`);
3538
let retryingFailed = false;
3639
try {
37-
execSync(`yarn test --timeout=${TIMEOUT}m ` + args.concat(retryingArgs).join(' '), { stdio: [0, 1, 2] });
40+
execSync(`yarn test --timeout=${TIMEOUT}m ` + args.concat(retryingArgs).join(' '), {
41+
stdio: [0, 1, 2],
42+
});
3843
log('retrying succeed');
3944
} catch (e) {
4045
retryingFailed = true;
@@ -44,7 +49,6 @@ function retryTests() {
4449
sendFailedTestsToAnalytics(failedTests).then(() => {
4550
if (retryingFailed) failAndExit();
4651
});
47-
4852
}
4953

5054
function log(...args) {
@@ -58,7 +62,6 @@ function failAndExit() {
5862
function sendFailedTestsToAnalytics(failedTests) {
5963
log('Sending analytics..');
6064
return new Promise((resolve, reject) => {
61-
6265
const options = {
6366
url: 'https://r2d2.streamlabs.com/slobs/data/ping',
6467
json: {
@@ -69,13 +72,13 @@ function sendFailedTestsToAnalytics(failedTests) {
6972
product: 'SLOBS',
7073
version: this.version,
7174
count: 1,
72-
uuid: 'test environment'
73-
}
74-
]
75-
}
75+
uuid: 'test environment',
76+
},
77+
],
78+
},
7679
};
7780

78-
const callback = (error) => {
81+
const callback = error => {
7982
if (error) {
8083
console.error('Analytics has not been sent');
8184
resolve();
@@ -88,3 +91,38 @@ function sendFailedTestsToAnalytics(failedTests) {
8891
request(options, callback);
8992
});
9093
}
94+
95+
/**
96+
* Fetch average execution timings for tests from DB
97+
* and save results to a file
98+
*/
99+
async function createTestTimingsFile() {
100+
const utilsServerUrl = 'https://slobs-users-pool.herokuapp.com';
101+
const token = process.env.SLOBS_TEST_USER_POOL_TOKEN;
102+
const testTimingsFile = 'test-dist/test-timings.json';
103+
rimraf.sync(testTimingsFile);
104+
105+
return new Promise((resolve, reject) => {
106+
fetch(`${utilsServerUrl}/testStats`, {
107+
method: 'get',
108+
headers: {
109+
Authorization: `Bearer ${token}`,
110+
'Content-Type': 'application/json',
111+
},
112+
})
113+
.then(res => {
114+
if (res.status !== 200) {
115+
reject('Unable to request the utility server', res);
116+
} else {
117+
res.json().then(data => {
118+
if (!fs.existsSync('test-dist')) {
119+
fs.mkdirSync('test-dist');
120+
}
121+
fs.writeFileSync(testTimingsFile, JSON.stringify(data));
122+
resolve();
123+
});
124+
}
125+
})
126+
.catch(e => reject(`Utility server is not available ${e}`));
127+
});
128+
}

0 commit comments

Comments
 (0)