Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix asyncworker test so it runs on 6.x #298

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion test/asyncworker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
'use strict';
const buildType = process.config.target_defaults.default_configuration;
const assert = require('assert');
const async_hooks = require('async_hooks');
const common = require('./common');

// we only check async hooks on 8.x an higher were
// they are closer to working properly
const nodeVersion = process.versions.node.split('.')[0]
let async_hooks = undefined;
function checkAsyncHooks() {
if (nodeVersion >=8) {
if (async_hooks == undefined) {
async_hooks = require('async_hooks');
}
return true;
}
return false;
}

test(require(`./build/${buildType}/binding.node`));
test(require(`./build/${buildType}/binding_noexcept.node`));

Expand Down Expand Up @@ -40,6 +53,22 @@ function installAsyncHooksForTest() {
}

function test(binding) {
if (!checkAsyncHooks()) {
binding.asyncworker.doWork(true, {}, function (e) {
assert.strictEqual(typeof e, 'undefined');
assert.strictEqual(typeof this, 'object');
assert.strictEqual(this.data, 'test data');
}, 'test data');

binding.asyncworker.doWork(false, {}, function (e) {
assert.ok(e instanceof Error);
assert.strictEqual(e.message, 'test error');
assert.strictEqual(typeof this, 'object');
assert.strictEqual(this.data, 'test data');
}, 'test data');
return;
}

{
const hooks = installAsyncHooksForTest();
const triggerAsyncId = async_hooks.executionAsyncId();
Expand Down