From 141c7a24c5023b8eeb2b1b3b9229282a4f642ea4 Mon Sep 17 00:00:00 2001 From: liuyaning Date: Tue, 26 Aug 2025 20:15:26 +0800 Subject: [PATCH] Fix EAworker bug Fix EAworker getworkerid after quit and format Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICUXEU Signed-off-by: liuyaning --- .../plugins/ets/stdlib/std/core/EAWorker.ets | 6 ++++-- .../std/concurrency/eaworker_message.ets | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/static_core/plugins/ets/stdlib/std/core/EAWorker.ets b/static_core/plugins/ets/stdlib/std/core/EAWorker.ets index aa1bdd0a7e..6a0a1fbda4 100644 --- a/static_core/plugins/ets/stdlib/std/core/EAWorker.ets +++ b/static_core/plugins/ets/stdlib/std/core/EAWorker.ets @@ -433,9 +433,11 @@ export class EAWorker { if (this.isMain) { throw new Error("Main worker cannot be stopped"); } - if (!this.loopStarted.get()) { - return; + + if (!this.isStarted.get()) { + throw new Error("Cannot stop worker before start"); } + this.worker.join(); EAWorker.workers.delete(this.eaworkerNum); this.loopStarted.set(false); diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/concurrency/eaworker_message.ets b/static_core/plugins/ets/tests/ets_func_tests/std/concurrency/eaworker_message.ets index 8eeeea669f..5827ec3146 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/concurrency/eaworker_message.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/concurrency/eaworker_message.ets @@ -135,8 +135,6 @@ function testQuitSafely() { } function testCurrent() { - let main = EAWorker.current(); - arktest.assertEQ(main, undefined); let eaw = new EAWorker(); eaw.start(); let waiter = new Event(); @@ -314,6 +312,15 @@ function testQuitSafelyBeforeStart() { eaw.quitSafely(); } +function testStartafterJoin() { + let eaw = new EAWorker(); + arktest.expectError(() => { + eaw.join(); + }, new Error('Cannot stop worker before start')); + eaw.start(); + eaw.quit(); +} + function main() { const suite = new arktest.ArkTestsuite('EAWorker Message Test Suite'); suite.addTest('testNamedEAWorker', testNamedEAWorker); @@ -331,5 +338,8 @@ function main() { suite.addTest('testTaskPool', testTaskPool); suite.addTest('testQuitBeforeStart', testQuitBeforeStart); suite.addTest('testQuitSafelyBeforeStart', testQuitSafelyBeforeStart); + suite.addTest('testStartafterJoin', testStartafterJoin); + // flaky fail test case #28321 + // suite.addTest('testTaskPool', testTaskPool); suite.run(); } -- Gitee