GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix test http upload timeout · nodejs/node@b1081db

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/pummel
    • test-http-upload-timeout.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/pummel/test-http-upload-timeout.js‎

Copy file name to clipboardExpand all lines: test/pummel/test-http-upload-timeout.js
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
// This tests setTimeout() by having multiple clients connecting and sending
2424
// data in random intervals. Clients are also randomly disconnecting until there
2525
// are no more clients left. If no false timeout occurs, this test has passed.
26-
require('../common');
26+
const common = require('../common');
2727
const http = require('http');
2828
const server = http.createServer();
2929
let connections = 0;
3030

31+
const ontimeout = common.mustNotCall('Unexpected timeout');
32+
3133
server.on('request', function(req, res) {
3234
req.socket.setTimeout(1000);
33-
req.socket.on('timeout', function() {
34-
throw new Error('Unexpected timeout');
35-
});
35+
req.socket.on('timeout', ontimeout);
3636
req.on('end', function() {
3737
connections--;
3838
res.writeHead(200);
39+
req.socket.off('timeout', ontimeout);
3940
res.end('done\n');
4041
if (connections === 0) {
4142
server.close();
@@ -47,7 +48,7 @@ server.on('request', function(req, res) {
4748
server.listen(0, function() {
4849
for (let i = 0; i < 10; i++) {
4950
connections++;
50-
51+
let count = 0;
5152
setTimeout(function() {
5253
const request = http.request({
5354
port: server.address().port,
@@ -56,13 +57,12 @@ server.listen(0, function() {
5657
});
5758

5859
function ping() {
59-
const nextPing = (Math.random() * 900).toFixed();
60-
if (nextPing > 600) {
60+
if (++count === 10) {
6161
request.end();
6262
return;
6363
}
6464
request.write('ping');
65-
setTimeout(ping, nextPing);
65+
setTimeout(ping, 300);
6666
}
6767
ping();
6868
}, i * 50);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.