Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: deflake test-http-destroyed-socket-write2 #36120

Merged
merged 1 commit into from Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions test/parallel/test-http-destroyed-socket-write2.js
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for .mustCall here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, otherwise there is no guarantee that the listener of the 'request' event added on line 33 is called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway we can use common.mustCall() there (line 33) if it is easier to grok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I misunderstood. Do you mean adding a callback to this req.write()? If so, I think it is not needed. It's out of the scope of the test.

}));

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());
});