Skip to content

Commit

Permalink
test: add workerdata-sharedarraybuffer test
Browse files Browse the repository at this point in the history
This functionality works but was previously untested.

PR-URL: #21180
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Fishrock123 committed Jun 12, 2018
1 parent 9219099 commit b766af9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/parallel/test-worker-workerdata-sharedarraybuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Flags: --expose-gc --experimental-worker
'use strict';

const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');

{
const sharedArrayBuffer = new SharedArrayBuffer(12);
const local = Buffer.from(sharedArrayBuffer);

const w = new Worker(`
const { parentPort, workerData } = require('worker_threads');
const local = Buffer.from(workerData.sharedArrayBuffer);
parentPort.on('message', () => {
local.write('world!', 6);
parentPort.postMessage('written!');
});
`, {
eval: true,
workerData: { sharedArrayBuffer }
});
w.on('message', common.mustCall(() => {
assert.strictEqual(local.toString(), 'Hello world!');
global.gc();
w.terminate();
}));
w.postMessage({});
// This would be a race condition if the memory regions were overlapping
local.write('Hello ');
}

0 comments on commit b766af9

Please sign in to comment.