| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| var common = require('../common'); | ||
| var assert = require('assert'); | ||
|
|
||
| var DELAY = 50; | ||
| var WINDOW = 5; | ||
|
|
||
| function nearly(a, b) { | ||
| if (Math.abs(a-b) > WINDOW) | ||
| assert.strictEqual(a, b); | ||
| } | ||
|
|
||
| function work(ms) { | ||
| var start = Date.now(); | ||
| while (Date.now() - start < ms); | ||
| } | ||
|
|
||
| function test() { | ||
| var start = Date.now(); | ||
| setTimeout(function() { | ||
| work(DELAY + 20); | ||
| setTimeout(function() { | ||
| nearly(DELAY*3+20, Date.now() - start); | ||
| }, DELAY); | ||
| }, DELAY); | ||
| } | ||
|
|
||
| test(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| var common = require('../common'); | ||
| var assert = require('assert'); | ||
|
|
||
| var ALLOWABLE_ERROR = 5; // [ms] | ||
|
|
||
| function nearly(a, b) { | ||
| if (Math.abs(a-b) > ALLOWABLE_ERROR) | ||
| assert.strictEqual(a, b); | ||
| } | ||
|
|
||
| function test(period, busyTime, expectedDelta, isUnref, next) { | ||
| var res = []; | ||
|
|
||
| var prev = Date.now(); | ||
| var interval = setInterval(function() { | ||
| var s = Date.now(); | ||
| while (Date.now() - s < busyTime); | ||
| var e = Date.now(); | ||
|
|
||
| res.push(s-prev); | ||
| if (res.length === 5) { | ||
| clearInterval(interval); | ||
| done(); | ||
| } | ||
|
|
||
| prev = e; | ||
| }, period); | ||
|
|
||
| if (isUnref) { | ||
| interval.unref(); | ||
| var blocker = setTimeout(function() { | ||
| assert(false, 'Interval works too long'); | ||
| }, Math.max(busyTime, period) * 6); | ||
| } | ||
|
|
||
| function done() { | ||
| if (blocker) clearTimeout(blocker); | ||
| nearly(period, res.shift()); | ||
| res.forEach(nearly.bind(null, expectedDelta)); | ||
| process.nextTick(next); | ||
| } | ||
| } | ||
|
|
||
| test(50, 10, 40, false, function() { // ref, simple | ||
| test(50, 10, 40, true, function() { // unref, simple | ||
| test(50, 100, 0, false, function() { // ref, overlay | ||
| test(50, 100, 0, true, function() {}); // unref, overlay | ||
| }); | ||
| }); | ||
| }); |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityUnfortunately, I don't fully understand what @bnoordhuis meant. However, the test runs without it, i.e. check it out correctly this._onTimeout.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.