Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
9491bb09
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9491bb09
编写于
6月 25, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 25, 2023
浏览文件
操作
浏览文件
下载
差异文件
!9039 worker and taskpool add worker terminate xts Test case
Merge pull request !9039 from coollixin/master
上级
4b241a90
4cb03b57
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
148 addition
and
7 deletion
+148
-7
commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js
...ool_lib_standard/entry/src/main/ets/test/TaskPool.test.js
+74
-0
commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/worker/worker.js
...taskpool_lib_standard/entry/src/main/ets/worker/worker.js
+20
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
...lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
+31
-7
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
...r_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
+23
-0
未找到文件。
commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js
浏览文件 @
9491bb09
...
...
@@ -14,6 +14,7 @@
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
taskpool
from
'
@ohos.taskpool
'
import
worker
from
'
@ohos.worker
'
export
default
function
TaskPoolTest
()
{
describe
(
'
ActsAbilityTest
'
,
function
()
{
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
...
...
@@ -1516,5 +1517,78 @@ describe('ActsAbilityTest', function () {
}
done
();
})
/**
* @tc.number : TaskPoolTestClass061
* @tc.name : Sync Function Cancel task
* @tc.desc : Test Simultaneous use taskpool and worker
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it
(
'
TaskPoolTestClass061
'
,
0
,
async
function
(
done
)
{
function
testTaskPool
()
{
function
addition
(
arg
)
{
"
use concurrent
"
return
arg
+
1
;
}
function
additionDelay
(
arg
)
{
"
use concurrent
"
var
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
3000
)
{
continue
;
}
return
arg
+
1
;
}
try
{
var
task1
=
new
taskpool
.
Task
(
additionDelay
,
100
);
var
task2
=
new
taskpool
.
Task
(
additionDelay
,
200
);
var
task3
=
new
taskpool
.
Task
(
addition
,
300
);
taskpool
.
execute
(
task1
)
taskpool
.
execute
(
task2
)
taskpool
.
execute
(
task3
)
var
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
1000
)
{
continue
;
}
for
(
let
i
=
1
;
i
<=
10
;
i
++
)
{
taskpool
.
cancel
(
task1
);
}
}
catch
(
e
)
{
console
.
info
(
"
taskpoolXTS061 catch error:
"
+
e
);
}
}
function
promiseCase
()
{
let
p
=
new
Promise
(
function
(
resolve
,
reject
)
{
setTimeout
(
function
()
{
resolve
(
0
)
},
100
)
}).
then
(
undefined
,
(
error
)
=>
{
})
return
p
}
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/worker.js
"
)
let
res
=
0
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
res
++
}
testTaskPool
();
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
ss
.
terminate
();
}
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
();
})
})
}
\ No newline at end of file
commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/worker/worker.js
0 → 100644
浏览文件 @
9491bb09
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
worker
from
'
@ohos.worker
'
;
const
parentPort
=
worker
.
workerPort
;
parentPort
.
onmessage
=
function
(
e
)
{
}
\ No newline at end of file
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
浏览文件 @
9491bb09
...
...
@@ -126,24 +126,24 @@ describe('threadWorkerTest', function () {
*/
it
(
'
threadWorker_constructor_test_005
'
,
0
,
async
function
(
done
)
{
var
ss
=
[]
let
flag
=
0
try
{
let
a
=
0
while
(
a
<=
8
)
{
ss
[
a
]
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker.js
"
)
ss
[
a
].
onexit
=
function
()
{
flag
+=
1
}
a
+=
1
}
}
catch
(
error
)
{
expect
(
error
.
name
==
"
BusinessError
"
).
assertTrue
()
let
msg
=
"
Worker initialization failure, the number of workers exceeds the maximum.
"
expect
(
error
.
message
).
assertEqual
(
msg
)
let
b
=
7
let
flag
=
0
while
(
b
>=
0
)
{
ss
[
b
].
onexit
=
function
()
{
flag
+=
1
}
let
b
=
0
while
(
b
<
8
)
{
ss
[
b
].
terminate
()
b
-
=
1
b
+
=
1
}
while
(
flag
!=
8
)
{
await
promiseCase
()
...
...
@@ -592,6 +592,30 @@ describe('threadWorkerTest', function () {
}
})
// check worker terminate is ok
/**
* @tc.name: threadWorker_terminate_test_004
* @tc.desc: Terminates the worker thread to stop the worker from receiving messages.
*/
it
(
'
threadWorker_terminate_test_004
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_002.js
"
)
let
res
=
0
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
res
++
}
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
ss
.
terminate
();
}
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
()
})
// check worker on function is ok
/**
* @tc.name: threadWorker_on_test_001
...
...
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
浏览文件 @
9491bb09
...
...
@@ -464,6 +464,29 @@ describe('WorkerTest', function () {
done
()
})
// check worker terminate is ok
/**
* @tc.name: worker_terminate_test_004
* @tc.desc: Terminates the worker thread to stop the worker from receiving messages.
* @tc.author: hanyuqing
*/
it
(
'
worker_terminate_test_004
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
entry/ets/workers/worker_002.js
"
)
let
res
=
0
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
res
++
}
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
ss
.
terminate
();
}
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
()
})
// check worker on function is ok
/**
* @tc.name: worker_on_test_001
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录