summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuigi Pinca <luigipinca@gmail.com>2020-11-14 18:46:19 +0100
committerBeth Griggs <bgriggs@redhat.com>2020-12-15 20:15:22 +0000
commit3e77536c6b7a67f6949857d2606b8b137aa2ab43 (patch)
tree15f6aa64bfcbc84253a16c8ce24cac79ffa662cc
parent8a7c2b951d7e78744c9bdb251b0877ced81cb6d0 (diff)
downloadnode-new-3e77536c6b7a67f6949857d2606b8b137aa2ab43.tar.gz
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: https://github.com/nodejs/node/pull/36120 Fixes: https://github.com/nodejs/node/issues/36081 Fixes: https://github.com/nodejs/node/issues/4066 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
-rw-r--r--test/parallel/test-http-destroyed-socket-write2.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/test/parallel/test-http-destroyed-socket-write2.js b/test/parallel/test-http-destroyed-socket-write2.js
index 49594bde6d..8511c43ddd 100644
--- a/test/parallel/test-http-destroyed-socket-write2.js
+++ b/test/parallel/test-http-destroyed-socket-write2.js
@@ -21,16 +21,20 @@
'use strict';
const common = require('../common');
-const assert = require('assert');
// Verify that ECONNRESET is raised when writing to a http request
// where the server has ended the socket.
+const assert = require('assert');
const http = require('http');
+
+const kResponseDestroyed = Symbol('kResponseDestroyed');
+
const server = http.createServer(function(req, res) {
- setImmediate(function() {
+ req.on('data', common.mustCall(function() {
res.destroy();
- });
+ server.emit(kResponseDestroyed);
+ }));
});
server.listen(0, function() {
@@ -40,11 +44,9 @@ server.listen(0, function() {
method: 'POST'
});
- function write() {
- req.write('hello', function() {
- setImmediate(write);
- });
- }
+ server.once(kResponseDestroyed, common.mustCall(function() {
+ req.write('hello');
+ }));
req.on('error', common.mustCall(function(er) {
assert.strictEqual(req.res, null);
@@ -73,6 +75,5 @@ server.listen(0, function() {
}));
req.on('response', common.mustNotCall());
-
- write();
+ req.write('hello', common.mustSucceed());
});