Skip to content

Commit 4746649

Browse files
lpincacodebytere
authored andcommitted
test: deflake test-http-destroyed-socket-write2
Ensure that the write occurs in the same tick where the socket is destroyed by the other peer. PR-URL: #36120 Fixes: #36081 Fixes: #4066 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
1 parent a367c0d commit 4746649

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test/parallel/test-http-destroyed-socket-write2.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121

2222
'use strict';
2323
const common = require('../common');
24-
const assert = require('assert');
2524

2625
// Verify that ECONNRESET is raised when writing to a http request
2726
// where the server has ended the socket.
2827

28+
const assert = require('assert');
2929
const http = require('http');
30+
31+
const kResponseDestroyed = Symbol('kResponseDestroyed');
32+
3033
const server = http.createServer(function(req, res) {
31-
setImmediate(function() {
34+
req.on('data', common.mustCall(function() {
3235
res.destroy();
33-
});
36+
server.emit(kResponseDestroyed);
37+
}));
3438
});
3539

3640
server.listen(0, function() {
@@ -40,11 +44,9 @@ server.listen(0, function() {
4044
method: 'POST'
4145
});
4246

43-
function write() {
44-
req.write('hello', function() {
45-
setImmediate(write);
46-
});
47-
}
47+
server.once(kResponseDestroyed, common.mustCall(function() {
48+
req.write('hello');
49+
}));
4850

4951
req.on('error', common.mustCall(function(er) {
5052
assert.strictEqual(req.res, null);
@@ -73,6 +75,5 @@ server.listen(0, function() {
7375
}));
7476

7577
req.on('response', common.mustNotCall());
76-
77-
write();
78+
req.write('hello', common.mustSucceed());
7879
});

0 commit comments

Comments
 (0)