Skip to content

Commit

Permalink
test: deflake test-http-destroyed-socket-write2
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Ricky Zhou <[email protected]>
  • Loading branch information
lpinca authored and BethGriggs committed Dec 15, 2020
1 parent 8a7c2b9 commit 3e77536
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions test/parallel/test-http-destroyed-socket-write2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -73,6 +75,5 @@ server.listen(0, function() {
}));

req.on('response', common.mustNotCall());

write();
req.write('hello', common.mustSucceed());
});

0 comments on commit 3e77536

Please sign in to comment.