GeezerVison is showing github.com — test: deflake test-worker-eventlooputil · nodejs/node@8554feb
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/sequential/test-worker-eventlooputil.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -95,13 +95,19 @@ function checkWorkerIdle(wElu) { |
95 | 95 | } |
96 | 96 |
|
97 | 97 | function checkWorkerActive() { |
| 98 | + // Reading the worker's ELU from this thread is not atomic: the worker's idle |
| 99 | + // time is read before the current time. If this thread stalls between the |
| 100 | + // two reads while the worker is idle, the stall is counted as worker active |
| 101 | + // time in `w` and then missing from `w2`. The duration of the call bounds it. |
| 102 | + const start = performance.now(); |
98 | 103 | const w = workerELU(); |
| 104 | + const skew = performance.now() - start; |
99 | 105 |
|
100 | 106 | metricsCh.port2.postMessage({ cmd: 'spin', dur: 50 }); |
101 | 107 | metricsCh.port2.once('message', mustCall((wElu) => { |
102 | 108 | const w2 = workerELU(w); |
103 | 109 |
|
104 | | - assert.ok(w2.active >= 50, `${w2.active} < 50`); |
| 110 | + assert.ok(w2.active >= 50 - skew, `${w2.active} < 50 - ${skew}`); |
105 | 111 | assert.ok(wElu.active >= 50, `${wElu.active} < 50`); |
106 | 112 | assert.ok(idleActive(wElu) < idleActive(w2), |
107 | 113 | `${idleActive(wElu)} >= ${idleActive(w2)}`); |
|