-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement process.exit(...) in the runtime
- Loading branch information
Showing
7 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { fail, ok, rejects, strictEqual } from 'assert'; | ||
|
||
let called = false; | ||
|
||
process.exit(9999); | ||
|
||
export const test = { | ||
async test(_, env) { | ||
// We don't really have a way to verifying that the correct log messages | ||
// we emitted. For now, we need to manually check the log out, and here | ||
// we check only that we received an internal error and that no other | ||
// lines of code ran after the process.exit call. | ||
await rejects(env.subrequest.fetch('http://example.org'), { | ||
message: /^The Node.js process.exit/, | ||
}); | ||
ok(!called); | ||
}, | ||
}; | ||
|
||
let fooCreateCount = 0; | ||
|
||
export const test2 = { | ||
async test(_, env) { | ||
// We don't really have a way to verifying that the correct log messages | ||
// we emitted. For now, we need to manually check the log out, and here | ||
// we check only that we received an internal error and that no other | ||
// lines of code ran after the process.exit call. | ||
{ | ||
const obj = env.foo.get( | ||
env.foo.idFromName('210bd0cbd803ef7883a1ee9d86cce06f') | ||
); | ||
await rejects(obj.fetch('http://example.org'), { | ||
message: /^The Node.js process.exit/, | ||
}); | ||
await rejects(obj.fetch('http://example.org'), { | ||
message: /^The Node.js process.exit/, | ||
}); | ||
// The durable object should have been created twice. | ||
strictEqual(fooCreateCount, 2); | ||
} | ||
}, | ||
}; | ||
|
||
export default { | ||
async fetch() { | ||
try { | ||
process.exit(123); | ||
} finally { | ||
called = true; | ||
} | ||
}, | ||
}; | ||
|
||
export class Foo { | ||
constructor() { | ||
fooCreateCount++; | ||
} | ||
|
||
fetch() { | ||
process.exit(123); | ||
fail('Should never get here.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
|
||
const unitTests :Workerd.Config = ( | ||
services = [ | ||
( name = "process-exit-test", | ||
worker = ( | ||
modules = [ | ||
(name = "worker", esModule = embed "process-exit-test.js") | ||
], | ||
compatibilityDate = "2024-10-01", | ||
compatibilityFlags = ["nodejs_compat"], | ||
durableObjectNamespaces = [ | ||
(className = "Foo", uniqueKey = "210bd0cbd803ef7883a1ee9d86cce06f"), | ||
], | ||
durableObjectStorage = (inMemory = void), | ||
bindings = [ | ||
(name = "subrequest", service = "process-exit-test"), | ||
(name = "foo", durableObjectNamespace = "Foo"), | ||
] | ||
) | ||
), | ||
], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters