Skip to content

Commit

Permalink
Fixing #37: registration pool termination issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Walter committed Apr 25, 2019
1 parent 7a561b9 commit 2e3a551
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ async function run () {
const { passed, failed, skipped } = await bff(config)

// Log the results of running the tests.
console.log('')
process.stdout.write('\n')
print.info(`${passed} passed. ${failed} failed. ${skipped} skipped.`)

// If any tests failed, exit with a non-zero exit code.
if (failed) {
process.exit(1)
}
process.exit(failed ? 1 : 0)
}

try {
run()
} catch (err) {
print.error(err)
process.exit(1)
}
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { toHookExec, getSnapshotState } = require('./lib')
* worker pool to be executed.
*/
function run (config) {
return new Promise(async resolve => {
return new Promise(async (resolve, reject) => {
// Create the run context using the passed configuration and defaults.
const context = {
...config,
Expand Down Expand Up @@ -99,6 +99,13 @@ function run (config) {
// for the current test file.
context.filesRegistered++

// Terminate the registration pool if all the test files have been
// registered.
if (context.filesRegistered === context.files.length) {
registrationPool.terminate()
.then(() => print.debug('Registration pool terminated'))
}

// Add the number of tests returned by test registration to the running
// total of all tests that need to be executed.
context.testsRegistered += tests.length
Expand Down Expand Up @@ -230,19 +237,12 @@ function run (config) {
resolve(context)
}
} catch (err) {
print.error(err)
reject(err)
}
})
})
} catch (err) {
print.error(err)
} finally {
// Terminate the registration pool if all the test files have been
// registered.
if (context.filesRegistered === context.files.length) {
registrationPool.terminate()
.then(() => print.debug('Registration pool terminated'))
}
reject(err)
}
})
}
Expand Down

0 comments on commit 2e3a551

Please sign in to comment.