| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 14e07c9 commit 380a5d5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,14 +3,8 @@ const common = require('../common'); | |||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const http = require('http'); | |
| 5 | 5 | ||
| 6 | - var ntimeouts = 0; | ||
| 7 | 6 | var nchunks = 0; | |
| 8 | 7 | ||
| 9 | - process.on('exit', function() { | ||
| 10 | - assert.equal(ntimeouts, 1); | ||
| 11 | - assert.equal(nchunks, 2); | ||
| 12 | - }); | ||
| 13 | - | ||
| 14 | 8 | const options = { | |
| 15 | 9 | method: 'GET', | |
| 16 | 10 | port: undefined, | |
@@ -21,7 +15,7 @@ const options = { | |||
| 21 | 15 | const server = http.createServer(function(req, res) { | |
| 22 | 16 | res.writeHead(200, {'Content-Length': '2'}); | |
| 23 | 17 | res.write('*'); | |
| 24 | - setTimeout(function() { res.end('*'); }, common.platformTimeout(100)); | ||
| 18 | + server.once('timeout', common.mustCall(function() { res.end('*'); })); | ||
| 25 | 19 | }); | |
| 26 | 20 | ||
| 27 | 21 | server.listen(0, options.host, function() { | |
@@ -30,19 +24,19 @@ server.listen(0, options.host, function() { | |||
| 30 | 24 | req.end(); | |
| 31 | 25 | ||
| 32 | 26 | function onresponse(res) { | |
| 33 | - req.setTimeout(50, function() { | ||
| 34 | - assert.equal(nchunks, 1); // should have received the first chunk by now | ||
| 35 | - ntimeouts++; | ||
| 36 | - }); | ||
| 27 | + req.setTimeout(50, common.mustCall(function() { | ||
| 28 | + assert.strictEqual(nchunks, 1); // should have received the first chunk | ||
| 29 | + server.emit('timeout'); | ||
| 30 | + })); | ||
| 37 | 31 | ||
| 38 | - res.on('data', function(data) { | ||
| 39 | - assert.equal('' + data, '*'); | ||
| 32 | + res.on('data', common.mustCall(function(data) { | ||
| 33 | + assert.strictEqual('' + data, '*'); | ||
| 40 | 34 | nchunks++; | |
| 41 | - }); | ||
| 35 | + }, 2)); | ||
| 42 | 36 | ||
| 43 | - res.on('end', function() { | ||
| 44 | - assert.equal(nchunks, 2); | ||
| 37 | + res.on('end', common.mustCall(function() { | ||
| 38 | + assert.strictEqual(nchunks, 2); | ||
| 45 | 39 | server.close(); | |
| 46 | - }); | ||
| 40 | + })); | ||
| 47 | 41 | } | |
| 48 | 42 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments