summaryrefslogtreecommitdiff
path: root/test/node-api/test_threadsafe_function/test.js
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2020-04-06 10:16:15 -0700
committerGabriel Schulhof <gabriel.schulhof@intel.com>2020-04-09 02:41:28 -0700
commitaeb7084fe6446350ec032e9819746126811bf44f (patch)
treeb1173c9ecd5c049f5af7298c181e587b437cd60d /test/node-api/test_threadsafe_function/test.js
parentb82d72c199e70a0c9fbeb6c06715ef8120b3de2f (diff)
downloadnode-new-aeb7084fe6446350ec032e9819746126811bf44f.tar.gz
n-api: detect deadlocks in thread-safe function
We introduce status `napi_would_deadlock` to be used as a return status by `napi_call_threadsafe_function` if the call is made with `napi_tsfn_blocking` on the main thread and the queue is full. PR-URL: https://github.com/nodejs/node/pull/32689 Fixes: https://github.com/nodejs/node/issues/32615 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'test/node-api/test_threadsafe_function/test.js')
-rw-r--r--test/node-api/test_threadsafe_function/test.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/test/node-api/test_threadsafe_function/test.js b/test/node-api/test_threadsafe_function/test.js
index 3603d79ee6..f5afe225f0 100644
--- a/test/node-api/test_threadsafe_function/test.js
+++ b/test/node-api/test_threadsafe_function/test.js
@@ -210,8 +210,13 @@ new Promise(function testWithoutJSMarshaller(resolve) {
}))
.then((result) => assert.strictEqual(result.indexOf(0), -1))
-// Start a child process to test rapid teardown
+// Start a child process to test rapid teardown.
.then(() => testUnref(binding.MAX_QUEUE_SIZE))
-// Start a child process with an infinite queue to test rapid teardown
-.then(() => testUnref(0));
+// Start a child process with an infinite queue to test rapid teardown.
+.then(() => testUnref(0))
+
+// Test deadlock prevention.
+.then(() => assert.deepStrictEqual(binding.TestDeadlock(), {
+ deadlockTest: 'Main thread would deadlock'
+}));