Skip to content

Commit

Permalink
test: add regression test for C++-created Buffer transfer
Browse files Browse the repository at this point in the history
Add a test for a regression that occurs when transferring some
`Buffer` objects that were created from C++ to a parent thread.

Fixes: #34126

PR-URL: #34140
Reviewed-By: Gerhard Stöbich <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed Jul 16, 2020
1 parent 9c98af7 commit a38219f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/parallel/test-worker-crypto-sign-transfer-result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

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

// Test that transferring the result of e.g. crypto.sign() from Worker to parent
// thread does not crash

const w = new Worker(`
const { parentPort } = require('worker_threads');
const crypto = require('crypto');
const assert = require('assert');
const fixtures = require(${JSON.stringify(fixturesPath)});
const keyPem = fixtures.readKey('rsa_private.pem');
const buf = crypto.sign('sha256', Buffer.from('hello'), keyPem);
assert.notStrictEqual(buf.byteLength, 0);
parentPort.postMessage(buf, [buf.buffer]);
assert.strictEqual(buf.byteLength, 0);
`, { eval: true });

w.on('message', common.mustCall((buf) => {
assert.notStrictEqual(buf.byteLength, 0);
}));
w.on('exit', common.mustCall());

0 comments on commit a38219f

Please sign in to comment.