()
| 30 | makeReq(); |
| 31 | |
| 32 | function makeReq() { |
| 33 | const request = client.request({ |
| 34 | ':path': '/foobar', |
| 35 | ':method': 'GET', |
| 36 | ':scheme': 'http', |
| 37 | ':authority': `localhost:${port}`, |
| 38 | }); |
| 39 | request.resume(); |
| 40 | request.end(); |
| 41 | |
| 42 | requests += 1; |
| 43 | |
| 44 | request.on('end', () => { |
| 45 | const diff = hrtime() - startTime; |
| 46 | const milliseconds = diff / NS_PER_MS; |
| 47 | if (server.timeout === 0n) { |
| 48 | // Set the timeout now. First connection will take significantly longer |
| 49 | // than subsequent connections, so using the duration of the first |
| 50 | // connection as the timeout should be robust. Double it anyway for good |
| 51 | // measure. |
| 52 | server.timeout = milliseconds * 2n; |
| 53 | startTime = hrtime(); |
| 54 | makeReq(); |
| 55 | } else if (milliseconds < server.timeout * 2n) { |
| 56 | makeReq(); |
| 57 | } else { |
| 58 | server.removeListener('timeout', mustNotCall); |
| 59 | server.close(); |
| 60 | client.close(); |
| 61 | } |
| 62 | }); |
| 63 | } |
| 64 | })); |
no test coverage detected