Skip to content

Commit

Permalink
Merge pull request #41 from Hexagon/async-fix-wip
Browse files Browse the repository at this point in the history
Fix non finished tests (WIP)
  • Loading branch information
Hexagon authored Aug 18, 2023
2 parents aecdfe2 + 95984bd commit f572d42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/core/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class Process {
} else {
this.pup.logger.log("stopping", `Stopping process, reason: ${reason}`, this.config)
}
this.killRunner(reason, "SIGTERM")
return this.killRunner(reason, "SIGTERM")
}).catch(() => false)

// Kill process after `terminateTimeout`
Expand All @@ -304,7 +304,7 @@ class Process {
// Using `any` because event payload is not typed yet
// deno-lint-ignore no-explicit-any
const onFinish = (ev: any) => {
if (ev.status?.pid == this.getStatus().pid && [ProcessState.FINISHED, ProcessState.EXHAUSTED].includes(this.status)) {
if (ev.status?.pid == this.getStatus().pid && [ProcessState.FINISHED, ProcessState.EXHAUSTED, ProcessState.ERRORED].includes(this.status)) {
abortTimers.abort()
this.pup.events.off("process_status_changed", onFinish)
// ToDo, resolve to whatever `killRunner()` returns, which is currently unavailable inside the `process_status_changed` event, so it's fixed to `true` by now
Expand Down
8 changes: 4 additions & 4 deletions test/core/pup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Deno.test({
// Stop process, assert stopped
const stopResult = await pup.stop(TEST_PROCESS_ID, "test")
assertEquals(stopResult, true)
assertEquals(testProcess?.getStatus().status, ProcessState.FINISHED)
assertEquals(testProcess?.getStatus().status, ProcessState.ERRORED)

// Block process, assert blocked
const blockResult = pup.block(TEST_PROCESS_ID, "test")
Expand All @@ -50,7 +50,7 @@ Deno.test({
// Start process, assert failed
const startResult2 = pup.start(TEST_PROCESS_ID, "test")
assertEquals(startResult2, false)
assertEquals(testProcess?.getStatus().status, ProcessState.FINISHED)
assertEquals(testProcess?.getStatus().status, ProcessState.ERRORED)

// Unblock process, assert unblocked
const unblockResult = pup.unblock(TEST_PROCESS_ID, "test")
Expand Down Expand Up @@ -101,7 +101,7 @@ Deno.test({
// Stop process, assert finished
const stopResult = await pup.stop(TEST_PROCESS_ID, "test")
assertEquals(stopResult, true)
assertEquals(testProcess?.getStatus().status, ProcessState.FINISHED)
assertEquals(testProcess?.getStatus().status, ProcessState.ERRORED)

// Block process, assert blocked
const blockResult = pup.block(TEST_PROCESS_ID, "test")
Expand All @@ -111,7 +111,7 @@ Deno.test({
// Start process, assert failed
const startResult2 = pup.start(TEST_PROCESS_ID, "test")
assertEquals(startResult2, false)
assertEquals(testProcess?.getStatus().status, ProcessState.FINISHED)
assertEquals(testProcess?.getStatus().status, ProcessState.ERRORED)

// Unblock process, assert unblocked
const unblockResult = pup.unblock(TEST_PROCESS_ID, "test")
Expand Down

0 comments on commit f572d42

Please sign in to comment.