Skip to content

Commit b920d45

Browse files
santigimenoTrott
authored andcommitted
test: refactor test-http-destroyed-socket-write2
Remove the limit of requests to be sent (128) as in some conditions it was reached without the `error` event being fired, causing the test to fail. Remove the initial timeout. Remove some variables used to check the validity of the test and replace them with `common.mustCall` and `common.fail` calls. PR-URL: #4970 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Klauke <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent c4b5a45 commit b920d45

File tree

1 file changed

+12
-46
lines changed

1 file changed

+12
-46
lines changed

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

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,13 @@ server.listen(common.PORT, function() {
1919
method: 'POST'
2020
});
2121

22-
var timer = setTimeout(write, 50);
23-
var writes = 0;
24-
2522
function write() {
26-
if (++writes === 128) {
27-
clearTimeout(timer);
28-
req.end();
29-
test();
30-
} else {
31-
req.write('hello', function() {
32-
timer = setImmediate(write);
33-
});
34-
}
23+
req.write('hello', function() {
24+
setImmediate(write);
25+
});
3526
}
3627

37-
var gotError = false;
38-
var sawData = false;
39-
var sawEnd = false;
40-
41-
req.on('error', function(er) {
42-
assert(!gotError);
43-
gotError = true;
28+
req.on('error', common.mustCall(function(er) {
4429
switch (er.code) {
4530
// This is the expected case
4631
case 'ECONNRESET':
@@ -56,39 +41,20 @@ server.listen(common.PORT, function() {
5641
'Writing to a torn down client should RESET or ABORT');
5742
break;
5843
}
59-
clearTimeout(timer);
60-
console.log('ECONNRESET was raised after %d writes', writes);
61-
test();
62-
});
44+
45+
assert.equal(req.output.length, 0);
46+
assert.equal(req.outputEncodings.length, 0);
47+
server.close();
48+
}));
6349

6450
req.on('response', function(res) {
6551
res.on('data', function(chunk) {
66-
console.error('saw data: ' + chunk);
67-
sawData = true;
52+
common.fail('Should not receive response data');
6853
});
6954
res.on('end', function() {
70-
console.error('saw end');
71-
sawEnd = true;
55+
common.fail('Should not receive response end');
7256
});
7357
});
7458

75-
var closed = false;
76-
77-
function test() {
78-
if (closed)
79-
return;
80-
81-
server.close();
82-
closed = true;
83-
84-
if (req.output.length || req.outputEncodings.length)
85-
console.error('bad happened', req.output, req.outputEncodings);
86-
87-
assert.equal(req.output.length, 0);
88-
assert.equal(req.outputEncodings, 0);
89-
assert(gotError);
90-
assert(!sawData);
91-
assert(!sawEnd);
92-
console.log('ok');
93-
}
59+
write();
9460
});

0 commit comments

Comments
 (0)