| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a61e5d8 commit ee333c9
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -931,6 +931,12 @@ function expectRequiredTLAError(err) { | |||
| 931 | 931 | } | |
| 932 | 932 | } | |
| 933 | 933 | ||
| 934 | + function sleepSync(ms) { | ||
| 935 | + const sab = new SharedArrayBuffer(4); | ||
| 936 | + const i32 = new Int32Array(sab); | ||
| 937 | + Atomics.wait(i32, 0, 0, ms); | ||
| 938 | + } | ||
| 939 | + | ||
| 934 | 940 | const common = { | |
| 935 | 941 | allowGlobals, | |
| 936 | 942 | buildType, | |
@@ -982,6 +988,7 @@ const common = { | |||
| 982 | 988 | skipIfInspectorDisabled, | |
| 983 | 989 | skipIfSQLiteMissing, | |
| 984 | 990 | spawnPromisified, | |
| 991 | + sleepSync, | ||
| 985 | 992 | ||
| 986 | 993 | get enoughTestMem() { | |
| 987 | 994 | return require('os').totalmem() > 0x70000000; /* 1.75 Gb */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,7 @@ const { | |||
| 50 | 50 | skipIfInspectorDisabled, | |
| 51 | 51 | skipIfSQLiteMissing, | |
| 52 | 52 | spawnPromisified, | |
| 53 | + sleepSync, | ||
| 53 | 54 | } = common; | |
| 54 | 55 | ||
| 55 | 56 | const getPort = () => common.PORT; | |
@@ -103,4 +104,5 @@ export { | |||
| 103 | 104 | skipIfInspectorDisabled, | |
| 104 | 105 | skipIfSQLiteMissing, | |
| 105 | 106 | spawnPromisified, | |
| 107 | + sleepSync, | ||
| 106 | 108 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,22 +1,19 @@ | |||
| 1 | 1 | // Test that timerify works with histogram option for synchronous functions. | |
| 2 | 2 | ||
| 3 | - import '../common/index.mjs'; | ||
| 3 | + import { sleepSync } from '../common/index.mjs'; | ||
| 4 | 4 | import assert from 'assert'; | |
| 5 | 5 | import { createHistogram, timerify } from 'perf_hooks'; | |
| 6 | - import { setTimeout as sleep } from 'timers/promises'; | ||
| 7 | - | ||
| 8 | - let _deadCode; | ||
| 9 | 6 | ||
| 10 | 7 | const histogram = createHistogram(); | |
| 11 | - const m = (a, b = 1) => { | ||
| 12 | - for (let i = 0; i < 1e3; i++) | ||
| 13 | - _deadCode = i; | ||
| 8 | + | ||
| 9 | + const m = () => { | ||
| 10 | + // Deterministic blocking delay (~1 millisecond). The histogram operates on | ||
| 11 | + // nanosecond precision, so this should be sufficient to prevent zero timings. | ||
| 12 | + sleepSync(1); | ||
| 14 | 13 | }; | |
| 15 | 14 | const n = timerify(m, { histogram }); | |
| 16 | 15 | assert.strictEqual(histogram.max, 0); | |
| 17 | 16 | for (let i = 0; i < 10; i++) { | |
| 18 | 17 | n(); | |
| 19 | - await sleep(10); | ||
| 20 | 18 | } | |
| 21 | - assert(_deadCode >= 0); | ||
| 22 | 19 | assert.notStrictEqual(histogram.max, 0); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments