From ce563b885c3e5a85f5e306793d59a9248e0a121f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 16 May 2022 18:07:36 +0200 Subject: [PATCH] Add debug logs --- eslint/babel-eslint-parser/src/client.cjs | 33 ++++++++++++++--------- scripts/integration-tests/e2e-babel.sh | 6 ++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/eslint/babel-eslint-parser/src/client.cjs b/eslint/babel-eslint-parser/src/client.cjs index a5e2ad74bda6..e0010bd7baef 100644 --- a/eslint/babel-eslint-parser/src/client.cjs +++ b/eslint/babel-eslint-parser/src/client.cjs @@ -64,26 +64,33 @@ exports.WorkerClient = class WorkerClient extends Client { constructor() { super((action, payload) => { + const wt = WorkerClient.#worker_threads; + this.#signal[0] = 0; - const subChannel = new WorkerClient.#worker_threads.MessageChannel(); + const subChannel = new wt.MessageChannel(); this.#worker.postMessage( { signal: this.#signal, port: subChannel.port1, action, payload }, [subChannel.port1], ); - Atomics.wait(this.#signal, 0, 0); - - let resp; - for (let i = 0; i < 100; i++) { - resp = WorkerClient.#worker_threads.receiveMessageOnPort( - subChannel.port2, - ); - if (resp) break; - Atomics.wait(this.#signal, 1, 0, 5); - } - - const message = resp.message; + let response; + let i = 0; + // Sometimes receiveMessageOnPort returns "undefined" instead of the + // actual response object. Try multiple times, with a timeout of 5ms + // on Atomic.wait starting from the second one. + do { + const wakeReason = Atomics.wait(this.#signal, 0, i ? Infinity : 5); + response = wt.receiveMessageOnPort(subChannel.port2); + + if (i > 0 || !response) { + console.log( + `WORKER COMMUNICATION: i=${i}, wakeReason=${wakeReason}, hasResponse=${!!response}`, + ); + } + } while (!response && i++ < 100); + + const { message } = response; if (message.error) throw Object.assign(message.error, message.errorData); else return message.result; }); diff --git a/scripts/integration-tests/e2e-babel.sh b/scripts/integration-tests/e2e-babel.sh index 995bcad41a45..e21d3b4063a1 100755 --- a/scripts/integration-tests/e2e-babel.sh +++ b/scripts/integration-tests/e2e-babel.sh @@ -33,6 +33,10 @@ startLocalRegistry "$PWD"/scripts/integration-tests/verdaccio-config.yml node "$PWD"/scripts/integration-tests/utils/bump-babel-dependencies.js # Build and test -YARN_ENABLE_IMMUTABLE_INSTALLS=false make -j test-ci +YARN_ENABLE_IMMUTABLE_INSTALLS=false make -j build-standalone-ci +for i in {1..50}; do + echo "RUN NUMBER $i" + BABEL_ENV=test yarn jest --maxWorkers=4 --ci +done cleanup