Skip to content

Commit 4c5457f

Browse files
Sebastian Plesciucaddaleax
Sebastian Plesciuc
authored andcommitted
test: fix flaky test-http-client-get-url
Fixed test-http-client-get-url by waiting on HTTP GET requests to finish before closing the server. PR-URL: #13516 Fixes: #13507 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent 812e0b0 commit 4c5457f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

test/parallel/test-http-client-get-url.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ const assert = require('assert');
2525
const http = require('http');
2626
const url = require('url');
2727
const URL = url.URL;
28+
const testPath = '/foo?bar';
2829

29-
const server = http.createServer(common.mustCall(function(req, res) {
30+
const server = http.createServer(common.mustCall((req, res) => {
3031
assert.strictEqual('GET', req.method);
31-
assert.strictEqual('/foo?bar', req.url);
32+
assert.strictEqual(testPath, req.url);
3233
res.writeHead(200, {'Content-Type': 'text/plain'});
3334
res.write('hello\n');
3435
res.end();
35-
server.close();
3636
}, 3));
3737

38-
server.listen(0, function() {
39-
const u = `http://127.0.0.1:${this.address().port}/foo?bar`;
40-
http.get(u);
41-
http.get(url.parse(u));
42-
http.get(new URL(u));
43-
});
38+
server.listen(0, common.localhostIPv4, common.mustCall(() => {
39+
const u = `http://${common.localhostIPv4}:${server.address().port}${testPath}`;
40+
http.get(u, common.mustCall(() => {
41+
http.get(url.parse(u), common.mustCall(() => {
42+
http.get(new URL(u), common.mustCall(() => {
43+
server.close();
44+
}));
45+
}));
46+
}));
47+
}));

0 commit comments

Comments
 (0)