mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
feat: add tests and default exit code for kill() on ChildProcess
This commit is contained in:
parent
e07d37eec6
commit
e134120afd
2 changed files with 24 additions and 5 deletions
|
@ -234,11 +234,9 @@ fn process_create(
|
||||||
.with_async_function("status", move |lua, ()| {
|
.with_async_function("status", move |lua, ()| {
|
||||||
let code_rx_rc_clone = Rc::clone(&code_rx_rc);
|
let code_rx_rc_clone = Rc::clone(&code_rx_rc);
|
||||||
async move {
|
async move {
|
||||||
let code = code_rx_rc_clone
|
// Exit code of 9 corresponds to SIGKILL, which should be the only case where
|
||||||
.borrow_mut()
|
// the receiver gets suddenly dropped
|
||||||
.recv()
|
let code = code_rx_rc_clone.borrow_mut().recv().await.unwrap_or(9);
|
||||||
.await
|
|
||||||
.expect("Code sender unexpectedly dropped");
|
|
||||||
|
|
||||||
TableBuilder::new(lua)?
|
TableBuilder::new(lua)?
|
||||||
.with_value("code", code)?
|
.with_value("code", code)?
|
||||||
|
|
21
tests/process/create/kill.luau
Normal file
21
tests/process/create/kill.luau
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
local process = require("@lune/process")
|
||||||
|
|
||||||
|
-- Killing a child process should work as expected
|
||||||
|
|
||||||
|
local message = "Hello, world!"
|
||||||
|
local child = process.create("cat")
|
||||||
|
|
||||||
|
child.stdin:write(message)
|
||||||
|
child.kill()
|
||||||
|
|
||||||
|
assert(child.status().code == 9, "Child process should have an exit code of 9 (SIGKILL)")
|
||||||
|
|
||||||
|
assert(
|
||||||
|
child.stdout:readToEnd() == message,
|
||||||
|
"Reading from stdout of child process should work even after kill"
|
||||||
|
)
|
||||||
|
|
||||||
|
local stdinWriteOk = pcall(function()
|
||||||
|
child.stdin:write(message)
|
||||||
|
end)
|
||||||
|
assert(not stdinWriteOk, "Writing to stdin of child process should not work after kill")
|
Loading…
Add table
Reference in a new issue