Skip to content

Commit 3d9bc01

Browse files
refackaddaleax
authored andcommitted
test,async_hooks: stabilize tests on Windows
PR-URL: #13381 Reviewed-By: Andreas Madsen <[email protected]>
1 parent 09eb588 commit 3d9bc01

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

‎test/async-hooks/test-emit-before-after.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ switch (process.argv[2]){
1616
}
1717

1818
constc1=spawnSync(process.execPath,[__filename,'test_invalid_async_id']);
19-
assert.strictEqual(c1.stderr.toString().split('\n')[0],
19+
assert.strictEqual(c1.stderr.toString().split(/[\r\n]+/g)[0],
2020
'Error: before(): asyncId or triggerAsyncId is less than '+
2121
'zero (asyncId: -1, triggerAsyncId: -1)');
2222
assert.strictEqual(c1.status,1);
2323

2424
constc2=spawnSync(process.execPath,[__filename,'test_invalid_trigger_id']);
25-
assert.strictEqual(c2.stderr.toString().split('\n')[0],
25+
assert.strictEqual(c2.stderr.toString().split(/[\r\n]+/g)[0],
2626
'Error: before(): asyncId or triggerAsyncId is less than '+
2727
'zero (asyncId: 1, triggerAsyncId: -1)');
2828
assert.strictEqual(c2.status,1);

‎test/async-hooks/test-graph.signal.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'use strict';
22

33
constcommon=require('../common');
4+
if(common.isWindows){
5+
common.skip('no signals on Windows');
6+
return;
7+
}
8+
49
constinitHooks=require('./init-hooks');
510
constverifyGraph=require('./verify-graph');
611
constexec=require('child_process').exec;

‎test/async-hooks/test-signalwrap.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
2-
32
constcommon=require('../common');
3+
4+
if(common.isWindows)returncommon.skip('no signals in Windows');
5+
46
constassert=require('assert');
57
constinitHooks=require('./init-hooks');
68
const{ checkInvocations }=require('./hook-checks');
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
'use strict';
2-
32
constcommon=require('../common');
43
constassert=require('assert');
4+
5+
// general hook test setup
56
consttick=require('./tick');
67
constinitHooks=require('./init-hooks');
78
const{ checkInvocations }=require('./hook-checks');
89

910
consthooks=initHooks();
1011
hooks.enable();
1112

12-
constReadStream=require('tty').ReadStream;
13-
constttyStream=newReadStream(0);
14-
15-
constas=hooks.activitiesOfTypes('TTYWRAP');
16-
assert.strictEqual(as.length,1);
17-
consttty=as[0];
13+
// test specific setup
14+
const{ ReadStream }=require('tty');
15+
constcheckInitOpts={init: 1};
16+
constcheckEndedOpts={init: 1,before: 1,after: 1,destroy: 1};
17+
18+
// test code
19+
//
20+
// listen to stdin except on Windows
21+
consttargetFD=common.isWindows ? 1 : 0;
22+
constttyStream=newReadStream(targetFD);
23+
constactivities=hooks.activitiesOfTypes('TTYWRAP');
24+
assert.strictEqual(activities.length,1);
25+
consttty=activities[0];
1826
assert.strictEqual(tty.type,'TTYWRAP');
1927
assert.strictEqual(typeoftty.uid,'number');
2028
assert.strictEqual(typeoftty.triggerAsyncId,'number');
21-
checkInvocations(tty,{init: 1},'when tty created');
22-
23-
ttyStream.end(common.mustCall(onend));
24-
25-
checkInvocations(tty,{init: 1},'when tty.end() was invoked ');
26-
27-
functiononend(){
28-
tick(2,common.mustCall(()=>
29-
checkInvocations(
30-
tty,{init: 1,before: 1,after: 1,destroy: 1},
31-
'when tty ended ')
32-
));
33-
}
34-
35-
process.on('exit',onexit);
36-
37-
functiononexit(){
29+
checkInvocations(tty,checkInitOpts,'when tty created');
30+
constdelayedOnCloseHandler=common.mustCall(()=>{
31+
checkInvocations(tty,checkEndedOpts,'when tty ended');
32+
});
33+
ttyStream.on('error',(err)=>assert.fail(err));
34+
ttyStream.on('close',common.mustCall(()=>
35+
tick(2,delayedOnCloseHandler)
36+
));
37+
ttyStream.destroy();
38+
checkInvocations(tty,checkInitOpts,'when tty.end() was invoked');
39+
40+
process.on('exit',()=>{
3841
hooks.disable();
3942
hooks.sanityCheck('TTYWRAP');
40-
checkInvocations(tty,{init: 1,before: 1,after: 1,destroy: 1},
41-
'when process exits');
42-
}
43+
checkInvocations(tty,checkEndedOpts,'when process exits');
44+
});

0 commit comments

Comments
(0)