| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 38b0c1f commit acfb29c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,11 +11,11 @@ assert(performance); | |||
| 11 | 11 | assert(performance.nodeTiming); | |
| 12 | 12 | assert.strictEqual(typeof performance.timeOrigin, 'number'); | |
| 13 | 13 | // Use a fairly large epsilon value, since we can only guarantee that the node | |
| 14 | - // process started up in 20 seconds. | ||
| 15 | - assert(Math.abs(performance.timeOrigin - Date.now()) < 20000); | ||
| 14 | + // process started up in 15 seconds. | ||
| 15 | + assert(Math.abs(performance.timeOrigin - Date.now()) < 15000); | ||
| 16 | 16 | ||
| 17 | 17 | const inited = performance.now(); | |
| 18 | - assert(inited < 20000); | ||
| 18 | + assert(inited < 15000); | ||
| 19 | 19 | ||
| 20 | 20 | { | |
| 21 | 21 | // Should work without throwing any errors | |
@@ -56,12 +56,43 @@ assert(inited < 20000); | |||
| 56 | 56 | assert.strictEqual(performance.nodeTiming.name, 'node'); | |
| 57 | 57 | assert.strictEqual(performance.nodeTiming.entryType, 'node'); | |
| 58 | 58 | ||
| 59 | + let timeoutDelay = 111; // An extra of 111 ms for the first call. | ||
| 60 | + | ||
| 61 | + function checkDelay(cb) { | ||
| 62 | + const defaultTimeout = 1; | ||
| 63 | + const timer = setInterval(checkDelay, defaultTimeout); | ||
| 64 | + const timeouts = 10; | ||
| 65 | + | ||
| 66 | + const now = getTime(); | ||
| 67 | + let resolved = 0; | ||
| 68 | + | ||
| 69 | + function checkDelay() { | ||
| 70 | + resolved++; | ||
| 71 | + if (resolved === timeouts) { | ||
| 72 | + clearInterval(timer); | ||
| 73 | + timeoutDelay = getTime() - now; | ||
| 74 | + cb(); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + function getTime() { | ||
| 80 | + const ts = process.hrtime(); | ||
| 81 | + return Math.ceil((ts[0] * 1e3) + (ts[1] / 1e6)); | ||
| 82 | + } | ||
| 83 | + | ||
| 59 | 84 | function checkNodeTiming(props) { | |
| 85 | + console.log(props); | ||
| 86 | + | ||
| 60 | 87 | for (const prop of Object.keys(props)) { | |
| 61 | 88 | if (props[prop].around !== undefined) { | |
| 62 | 89 | assert.strictEqual(typeof performance.nodeTiming[prop], 'number'); | |
| 63 | 90 | const delta = performance.nodeTiming[prop] - props[prop].around; | |
| 64 | - assert(Math.abs(delta) < 1000); | ||
| 91 | + const delay = 1000 + timeoutDelay; | ||
| 92 | + assert( | ||
| 93 | + Math.abs(delta) < delay, | ||
| 94 | + `${prop}: ${Math.abs(delta)} >= ${delay}` | ||
| 95 | + ); | ||
| 65 | 96 | } else { | |
| 66 | 97 | assert.strictEqual(performance.nodeTiming[prop], props[prop], | |
| 67 | 98 | `mismatch for performance property ${prop}: ` + | |
@@ -83,20 +114,22 @@ checkNodeTiming({ | |||
| 83 | 114 | loopExit: -1 | |
| 84 | 115 | }); | |
| 85 | 116 | ||
| 86 | - setTimeout(() => { | ||
| 87 | - checkNodeTiming({ | ||
| 88 | - name: 'node', | ||
| 89 | - entryType: 'node', | ||
| 90 | - startTime: 0, | ||
| 91 | - duration: { around: performance.now() }, | ||
| 92 | - nodeStart: { around: 0 }, | ||
| 93 | - v8Start: { around: 0 }, | ||
| 94 | - bootstrapComplete: { around: inited }, | ||
| 95 | - environment: { around: 0 }, | ||
| 96 | - loopStart: { around: inited }, | ||
| 97 | - loopExit: -1 | ||
| 98 | - }); | ||
| 99 | - }, 2000); | ||
| 117 | + checkDelay(() => { | ||
| 118 | + setTimeout(() => { | ||
| 119 | + checkNodeTiming({ | ||
| 120 | + name: 'node', | ||
| 121 | + entryType: 'node', | ||
| 122 | + startTime: 0, | ||
| 123 | + duration: { around: performance.now() }, | ||
| 124 | + nodeStart: { around: 0 }, | ||
| 125 | + v8Start: { around: 0 }, | ||
| 126 | + bootstrapComplete: { around: inited }, | ||
| 127 | + environment: { around: 0 }, | ||
| 128 | + loopStart: { around: inited }, | ||
| 129 | + loopExit: -1 | ||
| 130 | + }); | ||
| 131 | + }, 1000); | ||
| 132 | + }); | ||
| 100 | 133 | ||
| 101 | 134 | process.on('exit', () => { | |
| 102 | 135 | checkNodeTiming({ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments