| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5a4b6c4 commit 4a749c3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,10 +23,10 @@ | |||
| 23 | 23 | const common = require('../common'); | |
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | const http = require('http'); | |
| 26 | + const Countdown = require('../common/countdown'); | ||
| 26 | 27 | ||
| 27 | 28 | let name; | |
| 28 | 29 | const max = 3; | |
| 29 | - let count = 0; | ||
| 30 | 30 | ||
| 31 | 31 | const server = http.Server(common.mustCall((req, res) => { | |
| 32 | 32 | if (req.url === '/0') { | |
@@ -45,21 +45,23 @@ server.listen(0, common.mustCall(() => { | |||
| 45 | 45 | request(i); | |
| 46 | 46 | })); | |
| 47 | 47 | ||
| 48 | + const countdown = new Countdown(max, () => { | ||
| 49 | + assert(!http.globalAgent.sockets.hasOwnProperty(name)); | ||
| 50 | + assert(!http.globalAgent.requests.hasOwnProperty(name)); | ||
| 51 | + server.close(); | ||
| 52 | + }); | ||
| 53 | + | ||
| 48 | 54 | function request(i) { | |
| 49 | 55 | const req = http.get({ | |
| 50 | 56 | port: server.address().port, | |
| 51 | 57 | path: `/${i}` | |
| 52 | 58 | }, function(res) { | |
| 53 | 59 | const socket = req.socket; | |
| 54 | 60 | socket.on('close', common.mustCall(() => { | |
| 55 | - ++count; | ||
| 56 | - if (count < max) { | ||
| 61 | + countdown.dec(); | ||
| 62 | + if (countdown.remaining > 0) { | ||
| 57 | 63 | assert.strictEqual(http.globalAgent.sockets[name].includes(socket), | |
| 58 | 64 | false); | |
| 59 | - } else { | ||
| 60 | - assert(!http.globalAgent.sockets.hasOwnProperty(name)); | ||
| 61 | - assert(!http.globalAgent.requests.hasOwnProperty(name)); | ||
| 62 | - server.close(); | ||
| 63 | 65 | } | |
| 64 | 66 | })); | |
| 65 | 67 | res.resume(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments