From fd1ab40498b2d30621fb0222649155d5ef50784c Mon Sep 17 00:00:00 2001 From: buzhuyu Date: Mon, 31 Jul 2023 09:40:00 +0800 Subject: [PATCH] [4.0Beta2] add taskpool getTaskpoolInfo xts description:add taskpool getTaskpoolInfo xts issue:https://gitee.com/openharmony/interface_sdk-js/issues/I7P4T9 Signed-off-by: buzhuyu --- .../entry/src/main/ets/test/TaskPool.test.js | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js index 222795d39..ddbfbb345 100644 --- a/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js +++ b/commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js @@ -1525,5 +1525,159 @@ describe('ActsAbilityTest', function () { }, 3000); done(); }) + + /** + * @tc.number : TaskPoolTestClass066 + * @tc.name : Async Function GetTaskPoolInfo + * @tc.desc : Get the taskPoolInfo + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass066', 0, async function (done) { + async function currentFun() { + "use concurrent" + await new Promise((resolve, reject) => { + setTimeout(resolve, 500, "async operation 1") + }); + await new Promise((resolve, reject) => { + setTimeout(resolve, 500, "async operation 2") + }); + } + + let highCount = 0; + let mediumCount = 0; + let lowCount = 0; + let allCount = 100; + for (let i = 0; i < allCount; i++) { + let task1 = new taskpool.Task(currentFun); + let task2 = new taskpool.Task(currentFun); + let task3 = new taskpool.Task(currentFun); + taskpool.execute(task1, taskpool.Priority.LOW).then(() => { + lowCount++; + }).catch((e) => { + console.error("low task error: " + e); + }) + taskpool.execute(task2, taskpool.Priority.MEDIUM).then(() => { + mediumCount++; + }).catch((e) => { + console.error("medium task error: " + e); + }) + taskpool.execute(task3, taskpool.Priority.HIGH).then(() => { + highCount++; + }).catch((e) => { + console.error("high task error: " + e); + }) + } + + let start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + let taskpoolInfo = taskpool.getTaskPoolInfo(); + + let tid = 0; + let taskIds = []; + let priority = 0; + let taskId = 0; + let state = 0; + let duration = 0; + + for (let threadInfo of taskpoolInfo.threadInfos) { + tid += threadInfo.tid; + taskIds.length += threadInfo.taskIds.length; + priority += threadInfo.priority; + } + + for (let taskInfo of taskpoolInfo.taskInfos) { + taskId += taskInfo.taskId; + state += taskInfo.state; + duration += taskInfo.duration; + } + console.info("task duration is: " + duration); + expect(tid != 0); + expect(taskId.length != 0); + expect(priority != -1); + expect(taskId != 0); + expect(state != 0); + done(); + }) + + /** + * @tc.number : TaskPoolTestClass067 + * @tc.name : sync Function GetTaskPoolInfo + * @tc.desc : Get the taskPoolInfo + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('TaskPoolTestClass067', 0, async function (done) { + function delay() { + "use concurrent" + let start = new Date().getTime(); + while (new Date().getTime() - start < 500) { + continue; + } + } + + let highCount = 0; + let mediumCount = 0; + let lowCount = 0; + let allCount = 100; + for (let i = 0; i < allCount; i++) { + let task1 = new taskpool.Task(delay); + let task2 = new taskpool.Task(delay); + let task3 = new taskpool.Task(delay); + taskpool.execute(task1, taskpool.Priority.LOW).then(() => { + lowCount++; + }).catch((e) => { + console.error("low task error: " + e); + }) + taskpool.execute(task2, taskpool.Priority.MEDIUM).then(() => { + mediumCount++; + }).catch((e) => { + console.error("medium task error: " + e); + }) + taskpool.execute(task3, taskpool.Priority.HIGH).then(() => { + highCount++; + }).catch((e) => { + console.error("high task error: " + e); + }) + } + + let start = new Date().getTime(); + while (new Date().getTime() - start < 1000) { + continue; + } + + let taskpoolInfo = taskpool.getTaskPoolInfo(); + + let tid = 0; + let taskIds = []; + let priority = 0; + let taskId = 0; + let state = 0; + let duration = 0; + + for(let threadInfo of taskpoolInfo.threadInfos) { + tid += threadInfo.tid; + taskIds.length += threadInfo.taskIds.length; + priority += threadInfo.priority; + } + + for(let taskInfo of taskpoolInfo.taskInfos) { + taskId += taskInfo.taskId; + state += taskInfo.state; + duration += taskInfo.duration; + } + console.info("task duration is: " + duration); + expect(tid != 0); + expect(taskId.length != 0); + expect(priority != -1); + expect(taskId != 0); + expect(state != 0); + done(); + }) }) } \ No newline at end of file -- GitLab