Skip to content

Commit db7b27a

Browse files
Trottitaloacasas
authored andcommitted
test: refactor beforeExit tests
Combine and rename tests for the `beforeExit` event on `process`. The naming now more closely follows the de facto conventions of the project. The two tests were very similar and do not seem to benefit from being separate. PR-URL: #10581 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 33851d1 commit db7b27a

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

test/parallel/test-process-before-exit.js

-14
This file was deleted.

test/parallel/test-beforeexit-event.js test/parallel/test-process-beforeexit.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ function tryListen() {
2121
.listen(0)
2222
.on('listening', common.mustCall(function() {
2323
this.close();
24-
process.on('beforeExit', common.mustCall(() => {}));
24+
process.once('beforeExit', common.mustCall(tryRepeatedTimer));
2525
}));
2626
}
27+
28+
// test that a function invoked from the beforeExit handler can use a timer
29+
// to keep the event loop open, which can use another timer to keep the event
30+
// loop open, etc.
31+
function tryRepeatedTimer() {
32+
const N = 5;
33+
let n = 0;
34+
const repeatedTimer = common.mustCall(function() {
35+
if (++n < N)
36+
setTimeout(repeatedTimer, 1);
37+
}, N);
38+
setTimeout(repeatedTimer, 1);
39+
}

0 commit comments

Comments
 (0)