Skip to content

Commit f5e7738

Browse files
jasnelltargos
authored andcommittedOct 2, 2024
test: reduce the allocation size in test-worker-arraybuffer-zerofill
Test has been flaky with timeouts in CI. This is possibly due to the repeated large allocations on the main thread. This commit reduces the allocation size and makes a number of other cleanups. The main goal is to hopefully make this test more reliable / not-flaky. Also move the test to sequential. The frequent large allocations could be causing the test to be flaky if run parallel to other tests. PR-URL: #54839 Refs: #52274 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent f26cf09 commit f5e7738

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed
 

Diff for: ‎test/parallel/test-worker-arraybuffer-zerofill.js

-33
This file was deleted.

Diff for: ‎test/sequential/test-worker-arraybuffer-zerofill.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
require('../common');
3+
const Countdown = require('../common/countdown');
4+
const assert = require('assert');
5+
const { Worker } = require('worker_threads');
6+
const { describe, it, mock } = require('node:test');
7+
8+
describe('Allocating uninitialized ArrayBuffers ...', () => {
9+
it('...should not affect zero-fill in other threads', () => {
10+
const w = new Worker(`
11+
const { parentPort } = require('worker_threads');
12+
13+
function post() {
14+
const uint32array = new Uint32Array(64);
15+
parentPort.postMessage(uint32array.reduce((a, b) => a + b));
16+
}
17+
18+
setInterval(post, 0);
19+
`, { eval: true });
20+
21+
const fn = mock.fn(() => {
22+
// Continuously allocate memory in the main thread. The allocUnsafe
23+
// here sets a scope internally that indicates that the memory should
24+
// not be initialized. While this is happening, the other thread is
25+
// also allocating buffers that must remain zero-filled. The purpose
26+
// of this test is to ensure that the scope used to determine whether
27+
// to zero-fill or not does not impact the other thread.
28+
setInterval(() => Buffer.allocUnsafe(32 * 1024 * 1024), 0).unref();
29+
});
30+
31+
w.on('online', fn);
32+
33+
const countdown = new Countdown(100, () => {
34+
w.terminate();
35+
assert(fn.mock.calls.length > 0);
36+
});
37+
38+
w.on('message', (sum) => {
39+
assert.strictEqual(sum, 0);
40+
if (countdown.remaining) countdown.dec();
41+
});
42+
});
43+
});

0 commit comments

Comments
 (0)
Please sign in to comment.