forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improvements to various http tests
* Add common/countdown utility * Numerous improvements to http tests PR-URL: nodejs#14315 Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
Showing
26 changed files
with
394 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable required-modules */ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const kLimit = Symbol('limit'); | ||
const kCallback = Symbol('callback'); | ||
|
||
class Countdown { | ||
constructor(limit, cb) { | ||
assert.strictEqual(typeof limit, 'number'); | ||
assert.strictEqual(typeof cb, 'function'); | ||
this[kLimit] = limit; | ||
this[kCallback] = cb; | ||
} | ||
|
||
dec() { | ||
assert(this[kLimit] > 0, 'Countdown expired'); | ||
if (--this[kLimit] === 0) | ||
this[kCallback](); | ||
} | ||
|
||
get remaining() { | ||
return this[kLimit]; | ||
} | ||
} | ||
|
||
module.exports = Countdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const Countdown = require('../common/countdown'); | ||
|
||
let done = ''; | ||
|
||
const countdown = new Countdown(2, common.mustCall(() => done = true)); | ||
assert.strictEqual(countdown.remaining, 2); | ||
countdown.dec(); | ||
assert.strictEqual(countdown.remaining, 1); | ||
countdown.dec(); | ||
assert.strictEqual(countdown.remaining, 0); | ||
assert.strictEqual(done, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.