@@ -34,16 +34,8 @@ const http = require('http');
3434 assert . strictEqual ( req . signal , req . signal ) ;
3535}
3636
37- // Test 4: req.signal aborts when 'abort' event is emitted on req
38- {
39- const req = new http . IncomingMessage ( null ) ;
40- const signal = req . signal ;
41- assert . strictEqual ( signal . aborted , false ) ;
42- req . emit ( 'abort' ) ;
43- assert . strictEqual ( signal . aborted , true ) ;
44- }
4537
46- // Test 5 : res.signal on a client-side http.request() response (IncomingMessage).
38+ // Test 4 : res.signal on a client-side http.request() response (IncomingMessage).
4739{
4840 const server = http . createServer ( common . mustCall ( ( req , res ) => {
4941 res . writeHead ( 200 ) ;
@@ -68,3 +60,26 @@ const http = require('http');
6860 clientReq . end ( ) ;
6961 } ) ) ;
7062}
63+
64+ // Test 5: Client cancels a pending request.
65+ {
66+ const server = http . createServer ( common . mustCall ( ( req , res ) => {
67+ req . signal . onabort = common . mustCall ( ( ) => {
68+ assert . strictEqual ( req . signal . aborted , true ) ;
69+ server . close ( ) ;
70+ } ) ;
71+ res . flushHeaders ( ) ;
72+ } ) ) ;
73+
74+ server . listen ( 0 , common . mustCall ( ( ) => {
75+ const clientReq = http . request (
76+ { port : server . address ( ) . port } ,
77+ common . mustCall ( ( res ) => {
78+ res . on ( 'error' , ( ) => { } ) ;
79+ clientReq . destroy ( ) ;
80+ } ) ,
81+ ) ;
82+ clientReq . on ( 'error' , ( ) => { } ) ;
83+ clientReq . end ( ) ;
84+ } ) ) ;
85+ }
0 commit comments