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

Fix propagation of async hook ids through callbacks #1511

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ inline bool OtherIsInt(Napi::Number source) {
if ((argc != 0) && (passed_argv != NULL)) {\
args.assign(passed_argv, passed_argv + argc);\
}\
Napi::Value res = (callback).MakeCallback(Napi::Value(context), args); \
Napi::Value res = (callback).Call(Napi::Value(context), args); \
if (res.IsEmpty()) return __VA_ARGS__;

#define WORK_DEFINITION(name) \
Expand Down
42 changes: 42 additions & 0 deletions test/async_calls.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict"

var sqlite3 = require('..');
const assert = require("assert");
const { createHook, executionAsyncId } = require("async_hooks");


describe('async_hooks', function() {
let db;
let dbId;
let asyncHook;

beforeEach(function() {
db = new sqlite3.Database(':memory:');

asyncHook = createHook({
init(asyncId, type) {
if (dbId == null && type.startsWith("sqlite3.")) {
dbId = asyncId;
}
}
}).enable();
});

it('should support performance measuring with async hooks', function(done) {
db.run("DROP TABLE user", () => {
const cbId = executionAsyncId();
assert.strictEqual(cbId, dbId);
done();
});
});

afterEach(function() {
if (asyncHook != null) {
asyncHook.disable();
}
dbId = null;
if (db != null) {
db.close();
}
});
});