summaryrefslogtreecommitdiff
path: root/test/node-api/test_worker_buffer_callback/test-free-called.js
blob: 2a3cc9e47c22ff88817a955c04a739108ee042be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'use strict';
const common = require('../../common');
const path = require('path');
const assert = require('assert');
const { Worker } = require('worker_threads');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
const { getFreeCallCount } = require(binding);

// Test that buffers allocated with a free callback through our APIs are
// released when a Worker owning it exits.

const w = new Worker(`require(${JSON.stringify(binding)})`, { eval: true });

assert.strictEqual(getFreeCallCount(), 0);
w.on('exit', common.mustCall(() => {
  assert.strictEqual(getFreeCallCount(), 1);
}));