|
1 | 1 | 'use strict';
|
2 |
| -var assert = require('assert'); |
3 |
| -var common = require('../common'); |
4 |
| -var http = require('http'); |
| 2 | +const assert = require('assert'); |
| 3 | +const common = require('../common'); |
| 4 | +const http = require('http'); |
5 | 5 |
|
6 | 6 | var start;
|
7 |
| -var server = http.createServer(function(req, res) { |
| 7 | +const server = http.createServer(common.mustCall(function(req, res) { |
8 | 8 | req.resume();
|
9 | 9 | req.on('end', function() {
|
10 | 10 | res.end('Success');
|
11 | 11 | });
|
12 | 12 |
|
13 | 13 | server.close();
|
14 |
| -}); |
15 |
| - |
16 |
| -server.listen(common.PORT, 'localhost', function() { |
17 |
| - var interval_id = setInterval(function() { |
18 |
| - start = new Date(); |
19 |
| - if (start.getMilliseconds() > 100) |
20 |
| - return; |
21 |
| - |
22 |
| - console.log(start.toISOString()); |
23 |
| - var req = http.request({ |
24 |
| - 'host': 'localhost', |
25 |
| - 'port': common.PORT, |
26 |
| - 'agent': false, |
27 |
| - 'method': 'PUT' |
28 |
| - }); |
| 14 | +})); |
29 | 15 |
|
30 |
| - req.end('Test'); |
31 |
| - clearInterval(interval_id); |
32 |
| - }, 10); |
33 |
| -}); |
| 16 | +server.listen(common.PORT, 'localhost', common.mustCall(function() { |
| 17 | + start = new Date(); |
| 18 | + const req = http.request({ |
| 19 | + 'host': 'localhost', |
| 20 | + 'port': common.PORT, |
| 21 | + 'agent': false, |
| 22 | + 'method': 'PUT' |
| 23 | + }); |
| 24 | + req.end('Test'); |
| 25 | +})); |
34 | 26 |
|
35 | 27 | process.on('exit', function() {
|
36 |
| - var end = new Date(); |
37 |
| - console.log(end.toISOString()); |
38 |
| - assert.equal(start.getSeconds(), end.getSeconds()); |
39 |
| - assert(end.getMilliseconds() < 900); |
40 |
| - console.log('ok'); |
| 28 | + const end = new Date(); |
| 29 | + assert(end - start < 1000, 'Entire test should take less than one second'); |
41 | 30 | });
|
0 commit comments