| 39 | }); |
| 40 | |
| 41 | function runAb(opts, callback) { |
| 42 | const command = `ab ${opts} http://127.0.0.1:${server.address().port}/`; |
| 43 | exec(command, common.mustCall(function(err, stdout, stderr) { |
| 44 | if (err) { |
| 45 | if (/ab|apr/i.test(stderr)) { |
| 46 | common.printSkipMessage(`problem spawning \`ab\`.\n${stderr}`); |
| 47 | process.reallyExit(0); |
| 48 | } |
| 49 | throw err; |
| 50 | } |
| 51 | |
| 52 | let m = /Document Length:\s*(\d+) bytes/i.exec(stdout); |
| 53 | const documentLength = parseInt(m[1]); |
| 54 | |
| 55 | m = /Complete requests:\s*(\d+)/i.exec(stdout); |
| 56 | const completeRequests = parseInt(m[1]); |
| 57 | |
| 58 | m = /HTML transferred:\s*(\d+) bytes/i.exec(stdout); |
| 59 | const htmlTransferred = parseInt(m[1]); |
| 60 | |
| 61 | assert.strictEqual(bodyLength, documentLength); |
| 62 | assert.strictEqual(completeRequests * documentLength, htmlTransferred); |
| 63 | |
| 64 | if (callback) callback(); |
| 65 | })); |
| 66 | } |
| 67 | |
| 68 | server.listen(0, common.mustCall(function() { |
| 69 | runAb('-c 1 -n 10', common.mustCall(function() { |