Skip to content

Commit ea17cf4

Browse files
🐛✅ fix bs-wrapper tests termination
When sending a SIGTERM, yarn doesn't wait for its children before exiting[1]. This commit removes the use of `yarn` in bs-wrapper. This should be fine, because yarn was only used for setting the environment (mostly PATH). Since bs-wrapper is run via yarn scripts, the environment should already be set up. This commit also changes bs-wrapper to make sure to send SIGTERM only once if child process sends more data to STDOUT before exiting. [1]: yarnpkg/yarn#4667
1 parent f3f8ccc commit ea17cf4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

scripts/bs-wrapper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const request = require('request')
55

66
const AVAILABILITY_CHECK_DELAY = 30_000
77
const RUNNING_BUILDS_API = `https://${process.env.BS_USERNAME}:${process.env.BS_ACCESS_KEY}@api.browserstack.com/automate/builds.json?status=running`
8-
const COMMAND = `yarn ${process.argv.slice(2).join(' ')}`
8+
const COMMAND = process.argv.slice(2).join(' ')
99
const RETRY_DELAY = 30_000
1010
const MAX_RETRY_COUNT = 3
1111

@@ -54,20 +54,22 @@ function hasRunningBuild() {
5454
function runTests() {
5555
return new Promise((resolve) => {
5656
let logs = ''
57+
let isKilled = false
5758
const current = exec(COMMAND)
5859
current.stdout.pipe(process.stdout)
5960
current.stdout.on('data', (data) => {
6061
logs += data
6162

62-
if (hasSessionCreationFailure(logs)) {
63+
if (!isKilled && hasSessionCreationFailure(logs)) {
64+
isKilled = true
6365
current.kill('SIGTERM')
6466
}
6567
})
6668

6769
current.on('exit', (code) => {
6870
if (code === 0) {
6971
resolve(TEST_STATUS_SUCCESS)
70-
} else if (hasSessionCreationFailure(logs)) {
72+
} else if (isKilled || hasSessionCreationFailure(logs)) {
7173
resolve(TEST_STATUS_RECOVERABLE_FAILURE)
7274
} else {
7375
resolve(TEST_STATUS_DEFINITIVE_FAILURE)

0 commit comments

Comments
 (0)