@@ -36,6 +36,12 @@ fetch = async (...args) => {
3636
3737const fcgi = require ( '../../../index.js' ) ;
3838
39+ function timeoutSignal ( ms ) {
40+ const ctrl = new AbortController ( ) ;
41+ setTimeout ( ( ) => ctrl . abort ( ) , ms ) ;
42+ return ctrl . signal ;
43+ }
44+
3945describe ( 'echo server' , function setup ( ) {
4046 let httpURL ;
4147
@@ -112,7 +118,7 @@ describe('echo server', function setup() {
112118 } ) ;
113119
114120 it ( 'should answer with the request' , async ( ) => {
115- const res = await fetch ( httpURL ) ;
121+ const res = await fetch ( httpURL , { signal : timeoutSignal ( 1000 ) } ) ;
116122
117123 expect ( res . status ) . to . be . equal ( 200 ) ;
118124 expect ( res . headers . get ( 'Content-Type' ) ) . to . be . equal ( "application/json; charset=utf-8" ) ;
@@ -134,7 +140,8 @@ describe('echo server', function setup() {
134140
135141 const res = await fetch ( new URL ( reqPath , httpURL ) , {
136142 method : 'POST' ,
137- body : reqBody
143+ body : reqBody ,
144+ signal : timeoutSignal ( 1000 )
138145 } ) ;
139146
140147 expect ( res . status ) . to . be . equal ( 200 ) ;
@@ -155,7 +162,7 @@ describe('echo server', function setup() {
155162 reqURL . searchParams . set ( 'a' , 'b' ) ;
156163 reqURL . searchParams . set ( 'ca' , 'd' ) ;
157164
158- const res = await fetch ( reqURL ) ;
165+ const res = await fetch ( reqURL , { signal : timeoutSignal ( 1000 ) } ) ;
159166
160167 expect ( res . status ) . to . be . equal ( 200 ) ;
161168 expect ( res . headers . get ( 'Content-Type' ) ) . to . be . equal ( "application/json; charset=utf-8" ) ;
@@ -170,7 +177,8 @@ describe('echo server', function setup() {
170177 const authHdr = `Basic ${ Buffer . from ( "ArthurDent:I think I'm a sofa..." ) . toString ( 'base64' ) } ` ;
171178
172179 const res = await fetch ( httpURL , {
173- headers : { 'Authorization' : authHdr }
180+ headers : { 'Authorization' : authHdr } ,
181+ signal : timeoutSignal ( 1000 )
174182 } ) ;
175183
176184 expect ( res . status ) . to . be . equal ( 200 ) ;
@@ -192,7 +200,8 @@ describe('echo server', function setup() {
192200 'x_test_hdr' : hdr2 , // passes hyphens in CGI params
193201 'Content-Type' : "text/plain"
194202 } ,
195- body : reqBody
203+ body : reqBody ,
204+ signal : timeoutSignal ( 1000 )
196205 } ) ;
197206
198207 expect ( res . status ) . to . be . equal ( 200 ) ;
0 commit comments