Skip to content

Commit 963d7d7

Browse files
joyeecheungrichardlau
authored andcommitted
test: fix test-child-process-fork-net
The child processes are supposed to get 4 messages (2 ends, 2 writes). Previously the mustCall() wrapping the message listener attempts to match exactly 1 invocation which is bound to fail but could be swallowed if the child happens to be killed before the exit event is fired for the mustCall() check to work. In the CI, on some machines the kill() could happen after the child process finishes with the mustCall() check, resulting in EPERM errors in kill(). This patch fixes the mustCall() checks (updating the expected invocation count to 4) and swallow the errors when kill() fails, which should be fine because they are only there for cleanup. PR-URL: #51841 Refs: #51813 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 7eb6930 commit 963d7d7

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

test/parallel/test-child-process-fork-net.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
// This tests that a socket sent to the forked process works.
23+
// See https://github.com/nodejs/node/commit/dceebbfa
24+
2225
'use strict';
2326
const {
2427
mustCall,
@@ -65,7 +68,7 @@ if (process.argv[2] === 'child') {
6568
socket.on('finish', mustCall(() => {
6669
debug(`[${id}] socket finished ${m}`);
6770
}));
68-
}));
71+
}, 4));
6972

7073
process.on('message', mustCall((m) => {
7174
if (m !== 'close') return;
@@ -74,7 +77,7 @@ if (process.argv[2] === 'child') {
7477
debug(`[${id}] ending ${i}/${needEnd.length}`);
7578
endMe.end('end');
7679
});
77-
}));
80+
}, 4));
7881

7982
process.on('disconnect', mustCall(() => {
8083
debug(`[${id}] process disconnect, ending`);
@@ -146,9 +149,22 @@ if (process.argv[2] === 'child') {
146149
server.on('close', mustCall(function() {
147150
closeEmitted = true;
148151

149-
child1.kill();
150-
child2.kill();
151-
child3.kill();
152+
// Clean up child processes.
153+
try {
154+
child1.kill();
155+
} catch {
156+
debug('child process already terminated');
157+
}
158+
try {
159+
child2.kill();
160+
} catch {
161+
debug('child process already terminated');
162+
}
163+
try {
164+
child3.kill();
165+
} catch {
166+
debug('child process already terminated');
167+
}
152168
}));
153169

154170
server.listen(0, '127.0.0.1');

0 commit comments

Comments
 (0)