Skip to content

test: fix test http upload timeout #43935

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/pummel/test-http-upload-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
// This tests setTimeout() by having multiple clients connecting and sending
// data in random intervals. Clients are also randomly disconnecting until there
// are no more clients left. If no false timeout occurs, this test has passed.
require('../common');
const common = require('../common');
const http = require('http');
const server = http.createServer();
let connections = 0;

const ontimeout = common.mustNotCall('Unexpected timeout');

server.on('request', function(req, res) {
req.socket.setTimeout(1000);
req.socket.on('timeout', function() {
throw new Error('Unexpected timeout');
});
req.socket.on('timeout', ontimeout);
req.on('end', function() {
connections--;
res.writeHead(200);
req.socket.off('timeout', ontimeout);
res.end('done\n');
if (connections === 0) {
server.close();
Expand All @@ -47,7 +48,7 @@ server.on('request', function(req, res) {
server.listen(0, function() {
for (let i = 0; i < 10; i++) {
connections++;

let count = 0;
setTimeout(function() {
const request = http.request({
port: server.address().port,
Expand All @@ -56,13 +57,12 @@ server.listen(0, function() {
});

function ping() {
const nextPing = (Math.random() * 900).toFixed();
if (nextPing > 600) {
if (++count === 10) {
request.end();
return;
}
request.write('ping');
setTimeout(ping, nextPing);
setTimeout(ping, 300);
}
ping();
}, i * 50);
Expand Down