Skip to content

Commit 39f8e53

Browse files
committed
Revert "test updates for node 20"
This reverts commit 1b6e6ba.
1 parent 1b6e6ba commit 39f8e53

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

packages/server/src/__tests__/express4/expressSpecific.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ it('supporting doubly-encoded variables example from migration guide', async ()
193193
query: 'query Hello($s: String!){hello(s: $s)}',
194194
variables: '{malformed JSON}',
195195
})
196-
.expect(400, /in JSON at position 1/);
196+
.expect(400, 'Unexpected token m in JSON at position 1');
197197

198198
await server.stop();
199199
});

packages/server/src/__tests__/plugin/drainHttpServer/stoppable.test.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const a: any = require('awaiting');
3232
const request: any = require('requisition');
3333
import fs from 'fs';
3434
import { Stopper } from '../../../plugin/drainHttpServer/stoppable';
35+
import child from 'child_process';
3536
import path from 'path';
3637
import type { AddressInfo } from 'net';
3738
import { describe, it, expect, afterEach, beforeEach } from '@jest/globals';
@@ -135,9 +136,7 @@ Object.keys(schemes).forEach((schemeName) => {
135136
),
136137
);
137138
expect(err.code).toMatch(/ECONNREFUSED/);
138-
139-
const isNode20 = !!process.version.match(/^v20\./);
140-
expect(closed).toBe(isNode20 ? 1 : 0);
139+
expect(closed).toBe(0);
141140
});
142141
});
143142

@@ -302,21 +301,12 @@ Object.keys(schemes).forEach((schemeName) => {
302301

303302
if (schemeName === 'http') {
304303
it('with in-flights finishing before grace period ends', async () => {
305-
let stopper: Stopper;
306-
const killServerBarrier = resolvable();
307-
const server = http.createServer(async (_, res) => {
308-
res.writeHead(200);
309-
res.write('hello');
310-
311-
await killServerBarrier;
312-
res.end('world');
313-
await stopper.stop();
314-
});
315-
stopper = new Stopper(server);
316-
server.listen(0);
317-
const p = port(server);
318-
319-
const res = await request(`${schemeName}://localhost:${p}/`).agent(
304+
const file = path.join(__dirname, 'stoppable', 'server.js');
305+
const server = child.spawn('node', [file]);
306+
const [data] = await a.event(server.stdout, 'data');
307+
const port = +data.toString();
308+
expect(typeof port).toBe('number');
309+
const res = await request(`${schemeName}://localhost:${port}/`).agent(
320310
scheme.agent({ keepAlive: true }),
321311
);
322312
let gotBody = false;
@@ -330,13 +320,13 @@ Object.keys(schemes).forEach((schemeName) => {
330320
expect(gotBody).toBe(false);
331321

332322
// Tell the server that its request should finish.
333-
killServerBarrier.resolve();
323+
server.kill('SIGUSR1');
334324

335325
const body = await bodyPromise;
336326
expect(gotBody).toBe(true);
337327
expect(body).toBe('helloworld');
338328

339-
// Wait for server to close.
329+
// Wait for subprocess to go away.
340330
await a.event(server, 'close');
341331
});
342332
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This server is run by a test in stoppable.test.js. Its HTTP server should
2+
// only ever get one request. It will respond with a 200 and start writing its
3+
// body and then start the Stopper process with no hard-destroy grace period. It
4+
// will finish the request on SIGUSR1.
5+
6+
import http from 'http';
7+
import { Stopper } from '../../../../../dist/esm/plugin/drainHttpServer/stoppable.js';
8+
9+
let stopper;
10+
const server = http.createServer((req, res) => {
11+
res.writeHead(200);
12+
res.write('hello');
13+
process.on('SIGUSR1', () => res.end('world'));
14+
stopper.stop();
15+
});
16+
stopper = new Stopper(server);
17+
server.listen(0, () => console.log(server.address().port));

0 commit comments

Comments
 (0)