summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-02-15 11:17:31 +0100
committerAnna Henningsen <anna@addaleax.net>2019-02-17 18:07:30 +0100
commit586318aa9f70cdd0f5e0bc93b031ff68f572ed64 (patch)
treeea6f193e39702a738aa1a4f50ad62ac5d7c4494c /test
parent009efd0ec398455b7563020a684ef0c9f7f213a2 (diff)
downloadandroid-node-v8-586318aa9f70cdd0f5e0bc93b031ff68f572ed64.tar.gz
android-node-v8-586318aa9f70cdd0f5e0bc93b031ff68f572ed64.tar.bz2
android-node-v8-586318aa9f70cdd0f5e0bc93b031ff68f572ed64.zip
src: check HasCaught() in JSStream calls
`MakeCallback` can return an empty `MaybeLocal<>` even if no exception has been generated, in particular, if we were already terminating the current thread *before* the `TryCatch` scope started, which meant it would not have an exception to report. PR-URL: https://github.com/nodejs/node/pull/26124 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-worker-http2-generic-streams-terminate.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/parallel/test-worker-http2-generic-streams-terminate.js b/test/parallel/test-worker-http2-generic-streams-terminate.js
new file mode 100644
index 0000000000..234697fb4d
--- /dev/null
+++ b/test/parallel/test-worker-http2-generic-streams-terminate.js
@@ -0,0 +1,39 @@
+'use strict';
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+const assert = require('assert');
+const http2 = require('http2');
+const { Duplex } = require('stream');
+const { Worker, workerData } = require('worker_threads');
+
+// Tests the interaction between terminating a Worker thread and running
+// the native SetImmediate queue, which may attempt to perform multiple
+// calls into JS even though one already terminates the Worker.
+
+if (!workerData) {
+ const counter = new Int32Array(new SharedArrayBuffer(4));
+ const worker = new Worker(__filename, { workerData: { counter } });
+ worker.on('exit', common.mustCall(() => {
+ assert.strictEqual(counter[0], 1);
+ }));
+} else {
+ const { counter } = workerData;
+
+ // Start two HTTP/2 connections. This will trigger write()s call from inside
+ // the SetImmediate queue.
+ for (let i = 0; i < 2; i++) {
+ http2.connect('http://localhost', {
+ createConnection() {
+ return new Duplex({
+ write(chunk, enc, cb) {
+ Atomics.add(counter, 0, 1);
+ process.exit();
+ },
+ read() { }
+ });
+ }
+ });
+ }
+}