Skip to content

Commit 436fcf8

Browse files
committed
Add request timeouts to tests
1 parent b734494 commit 436fcf8

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

test/mocha/integration/echo.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ fetch = async (...args) => {
3636

3737
const 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+
3945
describe('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);

test/mocha/integration/multiwrite.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ fetch = async (...args) => {
3636

3737
const 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+
3945
describe('multiwrite server', function setup() {
4046
let httpURL;
4147

@@ -103,7 +109,7 @@ describe('multiwrite server', function setup() {
103109
});
104110

105111
it('should answer with the expected body', async () => {
106-
const res = await fetch(httpURL);
112+
const res = await fetch(httpURL, { signal: timeoutSignal(1000) });
107113
expect(res.status).to.be.equal(200);
108114

109115
const body = await res.text();

test/mocha/integration/multiwrite_no_content_length.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ fetch = async (...args) => {
3636

3737
const 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+
3945
describe('multiwrite server (no content-length)', function setup() {
4046
let httpURL;
4147

@@ -102,7 +108,7 @@ describe('multiwrite server (no content-length)', function setup() {
102108
});
103109

104110
it('should answer with the expected body', async () => {
105-
const res = await fetch(httpURL);
111+
const res = await fetch(httpURL, { signal: timeoutSignal(1000) });
106112
expect(res.status).to.be.equal(200);
107113

108114
const body = await res.text();

0 commit comments

Comments
 (0)