Skip to content

Commit e85f311

Browse files
manekinekkoruyadorno
authored andcommitted
test: refactor code to use AbortSignal.abort()
PR-URL: #37798 Refs: whatwg/dom#960 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Zijian Liu <[email protected]> Reviewed-By: Zeyu Yang <[email protected]>
1 parent 3376051 commit e85f311

16 files changed

+27
-64
lines changed

‎test/parallel/test-child-process-exec-abortcontroller-promisified.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ const waitCommand = common.isLinux ?
3737
}
3838

3939
{
40-
constac=newAbortController();
41-
const{ signal }=ac;
42-
ac.abort();
40+
constsignal=AbortSignal.abort();// Abort in advance
4341
constpromise=execPromisifed(waitCommand,{ signal });
4442

4543
assert.rejects(promise,/AbortError/,'pre aborted signal failed')

‎test/parallel/test-child-process-execFile-promisified-abortController.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const invalidArgTypeError ={
2929

3030
{
3131
// Verify that the signal option works properly when already aborted
32-
constac=newAbortController();
33-
const{ signal }=ac;
34-
ac.abort();
32+
constsignal=AbortSignal.abort();
3533

3634
assert.rejects(
3735
promisified(process.execPath,[echoFixture,0],{ signal }),

‎test/parallel/test-child-process-execfile.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ const execOpts ={encoding: 'utf8', shell: true };
6969

7070
{
7171
// Verify that does not spawn a child if already aborted
72-
constac=newAbortController();
73-
const{ signal }=ac;
74-
ac.abort();
72+
constsignal=AbortSignal.abort();
7573

7674
constcheck=common.mustCall((err)=>{
7775
assert.strictEqual(err.code,'ABORT_ERR');

‎test/parallel/test-child-process-fork-abort-signal.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ const{fork } = require('child_process');
2323
}
2424
{
2525
// Test passing an already aborted signal to a forked child_process
26-
constac=newAbortController();
27-
const{ signal }=ac;
28-
ac.abort();
26+
constsignal=AbortSignal.abort();
2927
constcp=fork(fixtures.path('child-process-stay-alive-forever.js'),{
3028
signal
3129
});
@@ -40,9 +38,7 @@ const{fork } = require('child_process');
4038

4139
{
4240
// Test passing a different kill signal
43-
constac=newAbortController();
44-
const{ signal }=ac;
45-
ac.abort();
41+
constsignal=AbortSignal.abort();
4642
constcp=fork(fixtures.path('child-process-stay-alive-forever.js'),{
4743
signal,
4844
killSignal: 'SIGKILL',

‎test/parallel/test-child-process-spawn-controller.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ const aliveScript = fixtures.path('child-process-stay-alive-forever.js');
2929

3030
{
3131
// Verify that passing an already-aborted signal works.
32-
constcontroller=newAbortController();
33-
const{ signal }=controller;
34-
35-
controller.abort();
32+
constsignal=AbortSignal.abort();
3633

3734
constcp=spawn(process.execPath,[aliveScript],{
3835
signal,

‎test/parallel/test-dgram-close-signal.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ const dgram = require('dgram');
2525

2626
{
2727
// Test close with pre-aborted signal.
28-
constcontroller=newAbortController();
29-
controller.abort();
30-
const{ signal }=controller;
28+
constsignal=AbortSignal.abort();
3129
constserver=dgram.createSocket({type: 'udp4', signal });
3230
server.on('close',common.mustCall());
3331
}

‎test/parallel/test-event-on-async-iterator.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,28 +248,26 @@ async function nodeEventTarget(){
248248

249249
asyncfunctionabortableOnBefore(){
250250
constee=newEventEmitter();
251-
constac=newAbortController();
252-
ac.abort();
251+
constabortedSignal=AbortSignal.abort();
253252
[1,{},null,false,'hi'].forEach((signal)=>{
254253
assert.throws(()=>on(ee,'foo',{ signal }),{
255254
code: 'ERR_INVALID_ARG_TYPE'
256255
});
257256
});
258-
assert.throws(()=>on(ee,'foo',{signal: ac.signal}),{
257+
assert.throws(()=>on(ee,'foo',{signal: abortedSignal}),{
259258
name: 'AbortError'
260259
});
261260
}
262261

263262
asyncfunctioneventTargetAbortableOnBefore(){
264263
constet=newEventTarget();
265-
constac=newAbortController();
266-
ac.abort();
264+
constabortedSignal=AbortSignal.abort();
267265
[1,{},null,false,'hi'].forEach((signal)=>{
268266
assert.throws(()=>on(et,'foo',{ signal }),{
269267
code: 'ERR_INVALID_ARG_TYPE'
270268
});
271269
});
272-
assert.throws(()=>on(et,'foo',{signal: ac.signal}),{
270+
assert.throws(()=>on(et,'foo',{signal: abortedSignal}),{
273271
name: 'AbortError'
274272
});
275273
}

‎test/parallel/test-events-once.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,16 @@ async function prioritizesEventEmitter(){
133133

134134
asyncfunctionabortSignalBefore(){
135135
constee=newEventEmitter();
136-
constac=newAbortController();
137136
ee.on('error',common.mustNotCall());
138-
ac.abort();
137+
constabortedSignal=AbortSignal.abort();
139138

140139
awaitPromise.all([1,{},'hi',null,false].map((signal)=>{
141140
returnrejects(once(ee,'foo',{ signal }),{
142141
code: 'ERR_INVALID_ARG_TYPE'
143142
});
144143
}));
145144

146-
returnrejects(once(ee,'foo',{signal: ac.signal}),{
145+
returnrejects(once(ee,'foo',{signal: abortedSignal}),{
147146
name: 'AbortError'
148147
});
149148
}
@@ -184,16 +183,15 @@ async function abortSignalRemoveListener(){
184183

185184
asyncfunctioneventTargetAbortSignalBefore(){
186185
constet=newEventTarget();
187-
constac=newAbortController();
188-
ac.abort();
186+
constabortedSignal=AbortSignal.abort();
189187

190188
awaitPromise.all([1,{},'hi',null,false].map((signal)=>{
191189
returnrejects(once(et,'foo',{ signal }),{
192190
code: 'ERR_INVALID_ARG_TYPE'
193191
});
194192
}));
195193

196-
returnrejects(once(et,'foo',{signal: ac.signal}),{
194+
returnrejects(once(et,'foo',{signal: abortedSignal}),{
197195
name: 'AbortError'
198196
});
199197
}

‎test/parallel/test-fs-promises-file-handle-readFile.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ async function doReadAndCancel(){
5858
constfileHandle=awaitopen(filePathForHandle,'w+');
5959
constbuffer=Buffer.from('Dogs running'.repeat(10000),'utf8');
6060
fs.writeFileSync(filePathForHandle,buffer);
61-
constcontroller=newAbortController();
62-
const{ signal }=controller;
63-
controller.abort();
61+
constsignal=AbortSignal.abort();
6462
awaitassert.rejects(readFile(fileHandle,{ signal }),{
6563
name: 'AbortError'
6664
});

‎test/parallel/test-fs-promises-readfile.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ async function validateReadFileProc(){
4343
}
4444

4545
functionvalidateReadFileAbortLogicBefore(){
46-
constcontroller=newAbortController();
47-
constsignal=controller.signal;
48-
controller.abort();
46+
constsignal=AbortSignal.abort();
4947
assert.rejects(readFile(fn,{ signal }),{
5048
name: 'AbortError'
5149
});

0 commit comments

Comments
(0)