Skip to content

Commit

Permalink
test-child-process-send-after-close.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgithub committed Feb 5, 2025
1 parent 1c30631 commit 719aa68
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ pub const Subprocess = struct {
IPClog("Subprocess#doSend", .{});
const ipc_data = &(this.ipc_data orelse {
if (this.hasExited()) {
return global.throw("Subprocess.send() cannot be used after the process has exited.", .{});
return global.ERR_IPC_CHANNEL_CLOSED("Subprocess.send() cannot be used after the process has exited.", .{}).throw();
} else {
return global.throw("Subprocess.send() can only be used if an IPC channel is open.", .{});
}
Expand Down
31 changes: 31 additions & 0 deletions test/js/node/test/parallel/test-child-process-send-after-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fixtures = require('../common/fixtures');

const fixture = fixtures.path('empty.js');
const child = cp.fork(fixture);

child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);

const testError = common.expectsError({
name: 'Error',
// message: 'Channel closed',
code: 'ERR_IPC_CHANNEL_CLOSED'
}, 2);

child.on('error', testError);

{
const result = child.send('ping');
assert.strictEqual(result, false);
}

{
const result = child.send('pong', testError);
assert.strictEqual(result, false);
}
}));

0 comments on commit 719aa68

Please sign in to comment.