Skip to content

Commit

Permalink
πŸ›βœ… fix bs-wrapper tests termination
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BenoitZugmeyer committed Dec 15, 2020
1 parent f3f8ccc commit 7379dc7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/bs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const request = require('request')

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

Expand Down Expand Up @@ -54,20 +54,22 @@ function hasRunningBuild() {
function runTests() {
return new Promise((resolve) => {
let logs = ''
let isKilled = false;
const current = exec(COMMAND)
current.stdout.pipe(process.stdout)
current.stdout.on('data', (data) => {
logs += data

if (hasSessionCreationFailure(logs)) {
if (!isKilled && hasSessionCreationFailure(logs)) {
isKilled = true;
current.kill('SIGTERM')
}
})

current.on('exit', (code) => {
if (code === 0) {
resolve(TEST_STATUS_SUCCESS)
} else if (hasSessionCreationFailure(logs)) {
} else if (isKilled || hasSessionCreationFailure(logs)) {
resolve(TEST_STATUS_RECOVERABLE_FAILURE)
} else {
resolve(TEST_STATUS_DEFINITIVE_FAILURE)
Expand Down

0 comments on commit 7379dc7

Please sign in to comment.