Skip to content

Commit

Permalink
test: reduce the allocation size in test-worker-arraybuffer-zerofill
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jasnell committed Sep 12, 2024
1 parent d9ca8b0 commit 4b2cab2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
33 changes: 0 additions & 33 deletions test/parallel/test-worker-arraybuffer-zerofill.js

This file was deleted.

43 changes: 43 additions & 0 deletions test/sequential/test-worker-arraybuffer-zerofill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';
require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
const { Worker } = require('worker_threads');
const { describe, it, mock } = require('node:test');

describe('Allocating uninitialized ArrayBuffers ...', () => {
it('...should not affect zero-fill in other threads', () => {
const w = new Worker(`
const { parentPort } = require('worker_threads');
function post() {
const uint32array = new Uint32Array(64);
parentPort.postMessage(uint32array.reduce((a, b) => a + b));
}
setInterval(post, 0);
`, { eval: true });

const fn = mock.fn(() => {
// Continuously allocate memory in the main thread. The allocUnsafe
// here sets a scope internally that indicates that the memory should
// not be initialized. While this is happening, the other thread is
// also allocating buffers that must remain zero-filled. The purpose
// of this test is to ensure that the scope used to determine whether
// to zero-fill or not does not impact the other thread.
setInterval(() => Buffer.allocUnsafe(32 * 1024 * 1024), 0).unref();
});

w.on('online', fn);

const countdown = new Countdown(100, () => {
w.terminate();
assert(fn.mock.calls.length > 0);
});

w.on('message', (sum) => {
assert.strictEqual(sum, 0);
if (countdown.remaining) countdown.dec();
});
});
});

0 comments on commit 4b2cab2

Please sign in to comment.