Skip to content

Commit

Permalink
Fixed propagation of async hook IDs through callbacks (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderfloh authored May 24, 2022
1 parent efee5f0 commit 4d31c19
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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();
}
});
});

0 comments on commit 4d31c19

Please sign in to comment.