Skip to content

Commit f5e7738

Browse files
jasnelltargos
authored andcommitted
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

2 files changed

Lines changed: 43 additions & 33 deletions

File tree

‎test/parallel/test-worker-arraybuffer-zerofill.js‎

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
require('../common');
3+
constCountdown=require('../common/countdown');
4+
constassert=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+
constw=newWorker(`
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+
constfn=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+
constcountdown=newCountdown(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)