Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
a81ba784
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看板
未验证
提交
a81ba784
编写于
3月 30, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 30, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8300 补充worker模块错误码用例和参数组合用例
Merge pull request !8300 from hwx1130639/cherry-pick-1680160673
上级
51c1dc0c
cd5d0e59
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
250 addition
and
12 deletion
+250
-12
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
...lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
+149
-7
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker.js
...rker_lib_standard/entry/src/main/ets/workers/newworker.js
+1
-5
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_022.js
..._lib_standard/entry/src/main/ets/workers/newworker_022.js
+26
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_023.js
..._lib_standard/entry/src/main/ets/workers/newworker_023.js
+26
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_024.js
..._lib_standard/entry/src/main/ets/workers/newworker_024.js
+27
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_025.js
..._lib_standard/entry/src/main/ets/workers/newworker_025.js
+21
-0
未找到文件。
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
浏览文件 @
a81ba784
...
@@ -459,20 +459,52 @@ describe('threadWorkerTest', function () {
...
@@ -459,20 +459,52 @@ describe('threadWorkerTest', function () {
done
()
done
()
})
})
// check worker handle error is ok
// check worker handle error is ok
/**
/**
* @tc.name: threadWorker_postMessage_test_007
* @tc.name: threadWorker_postMessage_test_007
* @tc.desc: Sends a message to the worker thread when throw error.
* @tc.desc: Sends a message to the worker thread when throw error.
*/
*/
it
(
'
threadWorker_postMessage_test_007
'
,
0
,
async
function
(
done
)
{
it
(
'
threadWorker_postMessage_test_007
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_007.js
"
);
let
isTerminate
=
false
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
;
}
try
{
try
{
const
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_007.js
"
)
ss
.
postMessage
();
ss
.
postMessage
()
}
catch
(
error
)
{
}
catch
(
error
)
{
expect
(
error
.
name
).
assertEqual
(
"
BusinessError
"
)
ss
.
terminate
();
expect
(
error
.
message
).
assertEqual
(
"
Worker messageObject must be not null with postMessage
"
)
while
(
!
isTerminate
)
{
await
promiseCase
();
}
expect
(
error
.
name
).
assertEqual
(
"
BusinessError
"
);
expect
(
error
.
message
).
assertEqual
(
"
Worker messageObject must be not null with postMessage
"
);
}
}
done
()
done
();
})
// check worker handle error is ok
/**
* @tc.name: threadWorker_postMessage_test_008
* @tc.desc: Sends a message to the worker thread when throw error.
*/
it
(
'
threadWorker_postMessage_test_008
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_007.js
"
);
let
isTerminate
=
false
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
;
}
try
{
ss
.
postMessage
(
"
123
"
,
"
123
"
);
}
catch
(
error
)
{
ss
.
terminate
();
while
(
!
isTerminate
)
{
await
promiseCase
();
}
expect
(
error
.
name
).
assertEqual
(
"
BusinessError
"
);
expect
(
error
.
message
).
assertEqual
(
"
transfer list must be an Array
"
);
}
done
();
})
})
// check worker terminate is ok
// check worker terminate is ok
...
@@ -2298,7 +2330,7 @@ describe('threadWorkerTest', function () {
...
@@ -2298,7 +2330,7 @@ describe('threadWorkerTest', function () {
const
data
=
Symbol
();
const
data
=
Symbol
();
ss
.
postMessage
(
data
);
ss
.
postMessage
(
data
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
info
(
"
worker:: recv error message:
"
+
error
.
message
)
console
.
info
(
"
worker:: recv error message:
"
+
error
.
message
)
;
while
(
!
flag
)
{
while
(
!
flag
)
{
await
promiseCase
();
await
promiseCase
();
}
}
...
@@ -2310,5 +2342,115 @@ describe('threadWorkerTest', function () {
...
@@ -2310,5 +2342,115 @@ describe('threadWorkerTest', function () {
expect
(
flag
).
assertTrue
();
expect
(
flag
).
assertTrue
();
done
();
done
();
})
})
// Check the postmessage of worker is ok.
/**
* @tc.name: threadWorker_worker_postmessage_test_001
* @tc.desc: Check the postmessage of worker is ok.
*/
it
(
'
threadWorker_worker_postmessage_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_022.js
"
);
let
res
=
""
;
let
flag
=
false
;
let
isTerminate
=
false
;
ss
.
onmessage
=
function
(
d
)
{
res
=
d
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
isTerminate
=
true
;
}
ss
.
postMessage
(
"
1
"
);
while
(
!
flag
)
{
await
promiseCase
();
}
ss
.
terminate
();
while
(
!
isTerminate
)
{
await
promiseCase
();
}
expect
(
res
).
assertEqual
(
"
Worker param count must be more than 1 with new
"
);
done
();
})
// Check the postmessage of worker is ok.
/**
* @tc.name: threadWorker_worker_postmessage_test_002
* @tc.desc: Check the postmessage of worker is ok.
*/
it
(
'
threadWorker_worker_postmessage_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_023.js
"
);
let
res
=
""
;
let
flag
=
false
;
let
isTerminate
=
false
;
ss
.
onmessage
=
function
(
d
)
{
res
=
d
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
isTerminate
=
true
;
}
ss
.
postMessage
(
"
1
"
);
while
(
!
flag
)
{
await
promiseCase
();
}
ss
.
terminate
();
while
(
!
isTerminate
)
{
await
promiseCase
();
}
expect
(
res
).
assertEqual
(
"
Transfer list must be an Array
"
);
done
();
})
// Check the postmessage of worker is ok.
/**
* @tc.name: threadWorker_worker_postmessage_test_003
* @tc.desc: Check the postmessage of worker is ok.
*/
it
(
'
threadWorker_worker_postmessage_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_024.js
"
);
let
res
=
""
;
let
flag
=
false
;
let
isTerminate
=
false
;
ss
.
onmessage
=
function
(
d
)
{
res
=
d
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
isTerminate
=
true
;
}
ss
.
postMessage
(
"
1
"
)
while
(
!
flag
)
{
await
promiseCase
();
}
ss
.
terminate
();
while
(
!
isTerminate
)
{
await
promiseCase
();
}
expect
(
res
).
assertEqual
(
"
Serializing an uncaught exception failed, failed to serialize message.
"
);
done
();
})
// Check the close of worker is ok.
/**
* @tc.name: threadWorker_worker_close_test_001
* @tc.desc: Check the close of worker is ok.
*/
it
(
'
threadWorker_worker_close_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_025.js
"
);
let
res
=
0
;
let
isTerminate
=
false
;
ss
.
onexit
=
function
()
{
res
+=
1
isTerminate
=
true
;
}
ss
.
postMessage
(
"
1
"
);
while
(
!
isTerminate
)
{
await
promiseCase
();
}
expect
(
res
==
1
).
assertTrue
();
done
();
})
})
})
}
}
\ No newline at end of file
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker.js
浏览文件 @
a81ba784
...
@@ -16,11 +16,7 @@
...
@@ -16,11 +16,7 @@
import
worker
from
'
@ohos.worker
'
;
import
worker
from
'
@ohos.worker
'
;
const
parentPort
=
worker
.
workerPort
;
const
parentPort
=
worker
.
workerPort
;
console
.
info
(
"
worker:: new version
"
)
console
.
info
(
"
worker:: new version
"
);
parentPort
.
onclose
=
function
()
{
console
.
info
(
"
worker::worker.js onclose
"
);
}
parentPort
.
onmessage
=
function
(
e
)
{
parentPort
.
onmessage
=
function
(
e
)
{
let
data
=
e
.
data
;
let
data
=
e
.
data
;
...
...
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_022.js
0 → 100644
浏览文件 @
a81ba784
/*
* Copyright (C) 2022 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
workerPort
=
worker
.
workerPort
;
workerPort
.
onmessage
=
function
(
e
)
{
try
{
workerPort
.
postMessage
();
}
catch
(
e
)
{
let
data
=
e
.
message
;
workerPort
.
postMessage
(
data
);
}
}
\ No newline at end of file
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_023.js
0 → 100644
浏览文件 @
a81ba784
/*
* Copyright (C) 2022 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
workerPort
=
worker
.
workerPort
;
workerPort
.
onmessage
=
function
(
e
)
{
try
{
workerPort
.
postMessage
(
"
123
"
,
"
123
"
);
}
catch
(
e
)
{
let
data
=
e
.
message
;
workerPort
.
postMessage
(
data
);
}
}
\ No newline at end of file
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_024.js
0 → 100644
浏览文件 @
a81ba784
/*
* Copyright (C) 2022 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
workerPort
=
worker
.
workerPort
;
workerPort
.
onmessage
=
function
(
e
)
{
try
{
const
symbol
=
Symbol
();
workerPort
.
postMessage
(
symbol
);
}
catch
(
e
)
{
let
data
=
e
.
message
;
workerPort
.
postMessage
(
data
);
}
}
\ No newline at end of file
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_025.js
0 → 100644
浏览文件 @
a81ba784
/*
* Copyright (C) 2022 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
workerPort
=
worker
.
workerPort
;
workerPort
.
onmessage
=
function
(
e
)
{
workerPort
.
close
();
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录