-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix stack traces of query() to include the async context (#1762) * rename tests so they are actually run * conditionally only run async stack trace tests on node 16+ * add stack trace to pg-native --------- Co-authored-by: Charmander <~@charmander.me>
- Loading branch information
1 parent
0dfd955
commit d59cd15
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/pg/test/integration/client/async-stack-trace-tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict' | ||
var helper = require('../test-helper') | ||
var pg = helper.pg | ||
|
||
process.on('unhandledRejection', function (e) { | ||
console.error(e, e.stack) | ||
process.exit(1) | ||
}) | ||
|
||
const suite = new helper.Suite() | ||
|
||
// these tests will only work for if --async-stack-traces is on, which is the default starting in node 16. | ||
const NODE_MAJOR_VERSION = +process.versions.node.split('.')[0]; | ||
if (NODE_MAJOR_VERSION >= 16) { | ||
suite.testAsync('promise API async stack trace in pool', async function outerFunction() { | ||
async function innerFunction() { | ||
const pool = new pg.Pool() | ||
await pool.query('SELECT test from nonexistent'); | ||
} | ||
try { | ||
await innerFunction(); | ||
throw Error("should have errored"); | ||
} catch (e) { | ||
const stack = e.stack; | ||
if(!e.stack.includes("innerFunction") || !e.stack.includes("outerFunction")) { | ||
throw Error("async stack trace does not contain wanted values: " + stack); | ||
} | ||
} | ||
}) | ||
|
||
suite.testAsync('promise API async stack trace in client', async function outerFunction() { | ||
async function innerFunction() { | ||
const client = new pg.Client() | ||
await client.connect(); | ||
try { | ||
await client.query('SELECT test from nonexistent'); | ||
} finally { | ||
client.end(); | ||
} | ||
} | ||
try { | ||
await innerFunction(); | ||
throw Error("should have errored"); | ||
} catch (e) { | ||
const stack = e.stack; | ||
if(!e.stack.includes("innerFunction") || !e.stack.includes("outerFunction")) { | ||
throw Error("async stack trace does not contain wanted values: " + stack); | ||
} | ||
} | ||
}) | ||
} |