Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
6e1faa9d
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看板
未验证
提交
6e1faa9d
编写于
6月 23, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
!3691 更新master分支上Worker模块的XTS用例
Merge pull request !3691 from hyq5234/OpenHarmony-3.1-Release
上级
cd50709c
61bc1586
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
834 addition
and
209 deletion
+834
-209
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_009.js
...er_lib_standard/src/main/js/default/workers/worker_009.js
+13
-0
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_010.js
...er_lib_standard/src/main/js/default/workers/worker_010.js
+8
-0
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_012.js
...er_lib_standard/src/main/js/default/workers/worker_012.js
+8
-0
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_0121.js
...r_lib_standard/src/main/js/default/workers/worker_0121.js
+4
-1
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_0122.js
...r_lib_standard/src/main/js/default/workers/worker_0122.js
+1
-1
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_013.js
...er_lib_standard/src/main/js/default/workers/worker_013.js
+8
-0
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_014.js
...er_lib_standard/src/main/js/default/workers/worker_014.js
+8
-0
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_015.js
...er_lib_standard/src/main/js/default/workers/worker_015.js
+4
-1
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_0151.js
...r_lib_standard/src/main/js/default/workers/worker_0151.js
+4
-1
compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js
...ntime/worker_lib_standard/src/main/js/test/Worker.test.js
+776
-205
未找到文件。
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_009.js
浏览文件 @
6e1faa9d
...
...
@@ -17,6 +17,7 @@ import worker from "@ohos.worker"
const
parentPort
=
worker
.
parentPort
;
var
ss
=
undefined
;
var
flag
=
false
;
parentPort
.
onmessage
=
function
(
e
)
{
let
data
=
e
.
data
;
...
...
@@ -24,8 +25,20 @@ parentPort.onmessage = function(e) {
case
"
new
"
:
ss
=
new
worker
.
Worker
(
"
workers/worker_0091.js
"
);
console
.
log
(
"
worker:: workerxx
"
);
ss
.
onexit
=
function
()
{
flag
=
true
;
}
parentPort
.
postMessage
(
ss
!=
null
);
break
;
case
"
wait
"
:
if
(
flag
)
{
parentPort
.
postMessage
(
"
terminate
"
);
}
break
;
case
"
terminate
"
:
flag
=
false
;
ss
.
terminate
();
break
;
default
:
break
;
}
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_010.js
浏览文件 @
6e1faa9d
...
...
@@ -29,6 +29,10 @@ parentPort.onmessage = function(e) {
backValue
=
ee
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
backValue
=
"
terminate
"
;
flag
=
true
;
}
ss
.
postMessage
(
data
.
value
);
break
;
case
"
wait
"
:
...
...
@@ -36,6 +40,10 @@ parentPort.onmessage = function(e) {
parentPort
.
postMessage
(
backValue
);
}
break
;
case
"
terminate
"
:
flag
=
false
;
ss
.
terminate
();
break
;
default
:
break
;
}
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_012.js
浏览文件 @
6e1faa9d
...
...
@@ -29,6 +29,10 @@ parentPort.onmessage = function(e) {
backValue
=
ee
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
backValue
=
"
terminate
"
;
flag
=
true
;
}
ss
.
postMessage
({
type
:
"
new
"
});
break
;
case
"
wait
"
:
...
...
@@ -36,6 +40,10 @@ parentPort.onmessage = function(e) {
parentPort
.
postMessage
(
backValue
);
}
break
;
case
"
terminate
"
:
flag
=
false
;
ss
.
terminate
();
break
;
default
:
break
;
}
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_0121.js
浏览文件 @
6e1faa9d
...
...
@@ -25,7 +25,10 @@ parentPort.onmessage = function(e) {
switch
(
data
.
type
)
{
case
"
new
"
:
ss
=
new
worker
.
Worker
(
"
workers/worker_0122.js
"
);
parentPort
.
postMessage
(
ss
!=
null
)
ss
.
terminate
();
ss
.
onexit
=
function
()
{
parentPort
.
postMessage
(
ss
!=
null
);
}
break
;
default
:
break
;
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_0122.js
浏览文件 @
6e1faa9d
...
...
@@ -21,5 +21,5 @@ var backValue = undefined;
var
flag
=
false
;
parentPort
.
onmessage
=
function
(
e
)
{
console
.
log
(
"
worker:: thrid worker onmessage
"
)
console
.
info
(
"
worker:: thrid worker onmessage
"
)
}
\ No newline at end of file
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_013.js
浏览文件 @
6e1faa9d
...
...
@@ -29,6 +29,10 @@ parentPort.onmessage = function(e) {
backValue
=
ee
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
backValue
=
"
terminate
"
;
flag
=
true
;
}
ss
.
postMessage
(
data
.
value
);
break
;
case
"
wait
"
:
...
...
@@ -36,6 +40,10 @@ parentPort.onmessage = function(e) {
parentPort
.
postMessage
(
backValue
);
}
break
;
case
"
terminate
"
:
flag
=
false
;
ss
.
terminate
();
break
;
default
:
break
;
}
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_014.js
浏览文件 @
6e1faa9d
...
...
@@ -29,6 +29,10 @@ parentPort.onmessage = function(e) {
backValue
=
ee
.
data
;
flag
=
true
;
}
ss
.
onexit
=
function
()
{
backValue
=
"
terminate
"
;
flag
=
true
;
}
ss
.
postMessage
(
data
.
value
);
break
;
case
"
wait
"
:
...
...
@@ -36,6 +40,10 @@ parentPort.onmessage = function(e) {
parentPort
.
postMessage
(
backValue
);
}
break
;
case
"
terminate
"
:
flag
=
false
;
ss
.
terminate
();
break
;
default
:
break
;
}
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_015.js
浏览文件 @
6e1faa9d
...
...
@@ -25,6 +25,9 @@ parentPort.onmessage = function(e) {
switch
(
data
.
type
)
{
case
"
new
"
:
ss
=
new
worker
.
Worker
(
"
workers/worker_0151.js
"
);
ss
.
onexit
=
function
()
{
parentPort
.
postMessage
(
backValue
);
// 16
}
ss
.
onmessage
=
function
(
ee
)
{
backValue
=
ee
.
data
;
// 16
flag
=
true
;
...
...
@@ -34,7 +37,7 @@ parentPort.onmessage = function(e) {
case
"
wait
"
:
ss
.
postMessage
({
type
:
"
wait
"
});
if
(
flag
)
{
parentPort
.
postMessage
(
backValue
);
// 16
ss
.
terminate
();
}
break
;
default
:
...
...
compileruntime/worker_lib_standard/src/main/js/default/workers/worker_0151.js
浏览文件 @
6e1faa9d
...
...
@@ -25,6 +25,9 @@ parentPort.onmessage = function(e) {
switch
(
data
.
type
)
{
case
"
new
"
:
ss
=
new
worker
.
Worker
(
"
workers/worker_0152.js
"
);
ss
.
onexit
=
function
()
{
parentPort
.
postMessage
(
backValue
);
// 16
}
ss
.
onmessage
=
function
(
ee
)
{
backValue
=
ee
.
data
;
flag
=
true
;
...
...
@@ -33,7 +36,7 @@ parentPort.onmessage = function(e) {
break
;
case
"
wait
"
:
if
(
flag
)
{
parentPort
.
postMessage
(
backValue
);
// 16
ss
.
terminate
();
}
break
;
default
:
...
...
compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js
浏览文件 @
6e1faa9d
...
...
@@ -16,7 +16,7 @@
// @ts-nocheck
import
app
from
'
@system.app
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
import
worker
from
"
@ohos.worker
"
;
import
worker
from
"
@ohos.worker
"
describe
(
'
workerTest
'
,
function
()
{
...
...
@@ -28,43 +28,120 @@ describe('workerTest', function () {
let
p
=
new
Promise
(
function
(
resolve
,
reject
)
{
setTimeout
(
function
()
{
resolve
()
},
100
)
;
},
100
)
}).
then
(
undefined
,
(
error
)
=>
{
})
return
p
}
// check worker constructor is ok
it
(
'
worker_constructor_test_001
'
,
0
,
function
()
{
/**
* @tc.name: worker_constructor_test_001
* @tc.desc: worker constructor to Creates a worker instance.
* @tc.author: hanyuqing
*/
it
(
'
worker_constructor_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
expect
(
ss
!=
null
).
assertTrue
()
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
it
(
'
worker_constructor_test_002
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
,{
name
:
"
second worker
"
,
shared
:
"
False
"
})
/**
* @tc.name: worker_constructor_test_002
* @tc.desc: worker constructor to Creates a worker instance.
* @tc.author: hanyuqing
*/
it
(
'
worker_constructor_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
,
{
name
:
"
second worker
"
,
shared
:
"
False
"
})
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
expect
(
ss
!=
null
).
assertTrue
()
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
it
(
'
worker_constructor_test_003
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
,{
type
:
"
classic
"
,
name
:
"
second worker
"
,
shared
:
"
false
"
})
/**
* @tc.name: worker_constructor_test_003
* @tc.desc: worker constructor to Creates a worker instance.
* @tc.author: hanyuqing
*/
it
(
'
worker_constructor_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
,
{
type
:
"
classic
"
,
name
:
"
second worker
"
,
shared
:
"
false
"
})
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
expect
(
ss
!=
null
).
assertTrue
()
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
it
(
'
worker_constructor_test_004
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
,{
type
:
"
classic
"
,
name
:
"
third worker
"
,
shared
:
"
true
"
})
/**
* @tc.name: worker_constructor_test_004
* @tc.desc: worker constructor to Creates a worker instance.
* @tc.author: hanyuqing
*/
it
(
'
worker_constructor_test_004
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
,
{
type
:
"
classic
"
,
name
:
"
third worker
"
,
shared
:
"
true
"
})
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
expect
(
ss
!=
null
).
assertTrue
()
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
// check postMessage is ok
// main post "hello world", will receive "hello world worker"
/**
* @tc.name: worker_postMessage_test_001
* @tc.desc: Sends a message to the worker thread.
* @tc.author: hanyuqing
*/
it
(
'
worker_postMessage_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_002.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_002.js
"
)
let
res
=
undefined
let
flag
=
false
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
res
=
e
.
data
;
res
=
e
.
data
flag
=
true
}
...
...
@@ -72,20 +149,35 @@ describe('workerTest', function () {
while
(
!
flag
)
{
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
hello world worker
"
)
done
()
})
// check postMessage is ok
// main post 12 , will receive 12 * 2 + 1
/**
* @tc.name: worker_postMessage_test_002
* @tc.desc: Sends a message to the worker thread.
* @tc.author: hanyuqing
*/
it
(
'
worker_postMessage_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_003.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_003.js
"
)
let
res
=
undefined
let
flag
=
false
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
res
=
e
.
data
;
res
=
e
.
data
flag
=
true
}
...
...
@@ -93,20 +185,35 @@ describe('workerTest', function () {
while
(
!
flag
)
{
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
25
)
done
()
})
// check postMessage is ok
// main post {message:"hello world"} , will receive {message:"hello world worker"}
/**
* @tc.name: worker_postMessage_test_003
* @tc.desc: Sends a message to the worker thread.
* @tc.author: hanyuqing
*/
it
(
'
worker_postMessage_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_004.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_004.js
"
)
let
res
=
undefined
let
flag
=
false
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
res
=
e
.
data
.
message
;
res
=
e
.
data
.
message
flag
=
true
}
...
...
@@ -114,19 +221,34 @@ describe('workerTest', function () {
while
(
!
flag
)
{
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
hello world worker
"
)
done
()
})
// check worker name is ok
/**
* @tc.name: worker_postMessage_test_004
* @tc.desc: Sends a message to the worker thread.
* @tc.author: hanyuqing
*/
it
(
'
worker_postMessage_test_004
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_005.js
"
,
{
name
:
"
zhangsan
"
})
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_005.js
"
,
{
name
:
"
zhangsan
"
})
let
res
=
undefined
let
flag
=
false
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
res
=
e
.
data
;
res
=
e
.
data
flag
=
true
}
...
...
@@ -134,23 +256,44 @@ describe('workerTest', function () {
while
(
!
flag
)
{
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
zhangsan
"
)
done
()
})
// check worker transfer buffer is ok
it
(
'
worker_postMessage_test_005
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_006.js
"
);
/**
* @tc.name: worker_postMessage_test_005
* @tc.desc: Sends a message to the worker thread.
* @tc.author: hanyuqing
*/
it
(
'
worker_postMessage_test_005
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_006.js
"
)
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
const
buffer
=
new
ArrayBuffer
(
8
)
expect
(
buffer
.
byteLength
).
assertEqual
(
8
)
ss
.
postMessage
(
buffer
,
[
buffer
])
let
length
=
undefined
;
let
exception
=
undefined
;
let
length
=
undefined
let
exception
=
undefined
try
{
length
=
buffer
.
byteLength
;
length
=
buffer
.
byteLength
}
catch
(
e
)
{
exception
=
e
.
message
;
exception
=
e
.
message
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
console
.
log
(
"
worker:: length is
"
+
length
)
...
...
@@ -161,55 +304,83 @@ describe('workerTest', function () {
}
else
{
expect
(
exception
).
assertEqual
(
"
IsDetachedBuffer
"
)
}
done
()
})
// check worker handle error is ok
/**
* @tc.name: worker_postMessage_test_006
* @tc.desc: Sends a message to the worker thread.
* @tc.author: hanyuqing
*/
it
(
'
worker_postMessage_test_006
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_007.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_007.js
"
)
let
res
=
undefined
let
flag
=
false
let
isTerminate
=
false
ss
.
onerror
=
function
(
e
)
{
res
=
e
.
message
;
res
=
e
.
message
flag
=
true
}
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
postMessage
(
"
hello world
"
)
while
(
!
flag
)
{
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
Error: 123
"
)
done
()
})
// check worker terminate is ok
/**
* @tc.name: worker_terminate_test_001
* @tc.desc: Terminates the worker thread to stop the worker from receiving messages.
* @tc.author: hanyuqing
*/
it
(
'
worker_terminate_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
res
=
0
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
res
++
;
res
++
}
ss
.
terminate
()
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
()
})
// check worker terminate is ok
/**
* @tc.name: worker_terminate_test_002
* @tc.desc: Terminates the worker thread to stop the worker from receiving messages.
* @tc.author: hanyuqing
*/
it
(
'
worker_terminate_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
res
=
0
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
res
++
;
res
++
}
// Repeated execution terminate
...
...
@@ -219,23 +390,28 @@ describe('workerTest', function () {
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
()
})
// check worker terminate is ok
/**
* @tc.name: worker_terminate_test_003
* @tc.desc: Terminates the worker thread to stop the worker from receiving messages.
* @tc.author: hanyuqing
*/
it
(
'
worker_terminate_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
res
=
0
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
res
++
;
res
++
}
ss
.
onmessage
=
function
(
e
)
{
res
++
;
res
++
}
ss
.
terminate
()
...
...
@@ -251,74 +427,151 @@ describe('workerTest', function () {
})
// check worker on function is ok
it
(
'
worker_on_test_001
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_on_test_001
* @tc.desc: Adds an event listener to the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_on_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
let
isTerminate
=
false
let
times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
on
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
1
)
done
()
})
// check worker on function is ok
it
(
'
worker_on_test_002
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_on_test_002
* @tc.desc: Adds an event listener to the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_on_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
let
isTerminate
=
false
let
times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
on
(
"
zhangsan
"
,
()
=>
{
times
--
;
times
--
})
ss
.
on
(
"
lisi
"
,
()
=>
{
times
++
;
times
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
0
)
done
()
})
// check worker on function is ok
it
(
'
worker_on_test_003
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_on_test_003
* @tc.desc: Adds an event listener to the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_on_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
;
let
times
=
0
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
on
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
}
console
.
log
(
"
times
"
+
times
);
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
console
.
log
(
"
times
"
+
times
)
expect
(
times
).
assertEqual
(
10
)
done
()
})
// check worker once function is ok
it
(
'
worker_once_test_001
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_once_test_001
* @tc.desc: Adds an event listener to the worker and removes the event listener automically
after it is invoked once.
* @tc.author: hanyuqing
*/
it
(
'
worker_once_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
let
isTerminate
=
false
let
times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
once
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
1
)
done
()
})
// check worker once function is ok
it
(
'
worker_once_test_002
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_once_test_002
* @tc.desc: Adds an event listener to the worker and removes the event listener automically
after it is invoked once.
* @tc.author: hanyuqing
*/
it
(
'
worker_once_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
let
isTerminate
=
false
let
times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
once
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
for
(
let
i
=
0
;
i
<
10
;
i
++
)
...
...
@@ -326,68 +579,132 @@ describe('workerTest', function () {
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
1
)
done
()
})
it
(
'
worker_once_test_003
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_once_test_003
* @tc.desc: Adds an event listener to the worker and removes the event listener automically
after it is invoked once.
* @tc.author: hanyuqing
*/
it
(
'
worker_once_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
;
let
times
=
0
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
once
(
"
zhangsan
"
,
()
=>
{
times
--
;
times
--
})
ss
.
once
(
"
lisi
"
,
()
=>
{
times
++
;
times
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
0
)
done
()
})
// check worker addEventListener function is ok
it
(
'
worker_addEventListener_test_001
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_addEventListener_test_001
* @tc.desc: Add an event listener to the Worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_addEventListener_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
let
isTerminate
=
false
let
times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
addEventListener
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
2
)
done
()
})
// check worker addEventListener function is ok
it
(
'
worker_addEventListener_test_002
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_addEventListener_test_002
* @tc.desc: Add an event listener to the Worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_addEventListener_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
;
let
times
=
0
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
addEventListener
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
ss
.
addEventListener
(
"
lisi
"
,
()
=>
{
times
++
;
times
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
2
)
done
()
})
// check worker addEventListener function is ok
it
(
'
worker_addEventListener_test_003
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_addEventListener_test_003
* @tc.desc: Add an event listener to the Worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_addEventListener_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
times
=
0
let
isTerminate
=
false
let
times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
addEventListener
(
"
zhangsan
"
,
()
=>
{
times
++
;
times
++
})
for
(
let
i
=
0
;
i
<
10
;
i
++
)
...
...
@@ -395,40 +712,73 @@ describe('workerTest', function () {
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
times
).
assertEqual
(
10
)
done
()
})
// check worker off function is ok
it
(
'
worker_off_test_001
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_off_test_001
* @tc.desc: Removes an event listener to the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_off_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
zhangSanTimes
=
0
let
isTerminate
=
false
let
zhangsan_times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
on
(
"
zhangsan
"
,
()
=>
{
zhang
san_times
++
;
zhang
SanTimes
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhang
san_t
imes
).
assertEqual
(
1
)
expect
(
zhang
SanT
imes
).
assertEqual
(
1
)
ss
.
off
(
"
zhangsan
"
)
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhangsan_times
).
assertEqual
(
1
)
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
zhangSanTimes
).
assertEqual
(
1
)
done
()
})
// check worker off function is ok
it
(
'
worker_off_test_002
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_off_test_002
* @tc.desc: Removes an event listener to the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_off_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
zhangsan_times
=
0
;
let
zhangSanTimes
=
0
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
on
(
"
zhangsan
"
,
()
=>
{
zhang
san_times
++
;
zhang
SanTimes
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhang
san_t
imes
).
assertEqual
(
2
)
expect
(
zhang
SanT
imes
).
assertEqual
(
2
)
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
...
...
@@ -436,40 +786,74 @@ describe('workerTest', function () {
}
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhangsan_times
).
assertEqual
(
2
)
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
zhangSanTimes
).
assertEqual
(
2
)
done
()
})
// check worker removeEventListener function is ok
it
(
'
worker_removeListener_test_001
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_removeListener_test_001
* @tc.desc: Removes an event defined for the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_removeListener_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
zhangSanTimes
=
0
let
isTerminate
=
false
let
zhangsan_times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
addEventListener
(
"
zhangsan
"
,
()
=>
{
zhang
san_times
++
;
zhang
SanTimes
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhang
san_t
imes
).
assertEqual
(
1
)
expect
(
zhang
SanT
imes
).
assertEqual
(
1
)
ss
.
removeEventListener
(
"
zhangsan
"
)
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhangsan_times
).
assertEqual
(
1
)
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
zhangSanTimes
).
assertEqual
(
1
)
done
()
})
// check worker removeEventListener function is ok
it
(
'
worker_removeListener_test_002
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_removeListener_test_002
* @tc.desc: Removes an event defined for the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_removeListener_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
zhangsan_times
=
0
;
let
zhangSanTimes
=
0
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
addEventListener
(
"
zhangsan
"
,
()
=>
{
zhang
san_times
++
;
zhang
SanTimes
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhang
san_t
imes
).
assertEqual
(
2
)
expect
(
zhang
SanT
imes
).
assertEqual
(
2
)
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
...
...
@@ -477,73 +861,107 @@ describe('workerTest', function () {
}
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhangsan_times
).
assertEqual
(
2
)
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
zhangSanTimes
).
assertEqual
(
2
)
done
()
})
// check worker removeAllListener function is ok
it
(
'
worker_removeListener_test_003
'
,
0
,
function
()
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
/**
* @tc.name: worker_removeListener_test_003
* @tc.desc: Removes an event defined for the worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_removeListener_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker.js
"
)
let
zhangSanTimes
=
0
let
isTerminate
=
false
let
zhangsan_times
=
0
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
addEventListener
(
"
zhangsan
"
,
()
=>
{
zhang
san_times
++
;
zhang
SanTimes
++
})
let
li
si_times
=
0
;
let
li
SiTimes
=
0
ss
.
addEventListener
(
"
lisi
"
,
()
=>
{
li
si_times
++
;
li
SiTimes
++
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhang
san_t
imes
).
assertEqual
(
2
)
expect
(
zhang
SanT
imes
).
assertEqual
(
2
)
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
expect
(
li
si_t
imes
).
assertEqual
(
2
)
expect
(
li
SiT
imes
).
assertEqual
(
2
)
ss
.
removeAllListener
()
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
ss
.
dispatchEvent
({
type
:
"
zhangsan
"
})
expect
(
zhang
san_t
imes
).
assertEqual
(
2
)
expect
(
zhang
SanT
imes
).
assertEqual
(
2
)
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
ss
.
dispatchEvent
({
type
:
"
lisi
"
})
expect
(
lisi_times
).
assertEqual
(
2
)
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
liSiTimes
).
assertEqual
(
2
)
done
()
})
// check parentPort.close is ok
/**
* @tc.name: worker_parentPortClose_test_001
* @tc.desc: Close the worker thread to stop the worker from receiving messages.
* @tc.author: hanyuqing
*/
it
(
'
worker_parentPortClose_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
let
res
=
0
let
flag
=
false
;
let
flag
=
false
ss
.
onexit
=
function
(
e
)
{
res
++
;
flag
=
true
;
res
++
flag
=
true
}
ss
.
postMessage
(
"
abc
"
)
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
()
})
// check parentPort.close is ok
/**
* @tc.name: worker_parentPortClose_test_002
* @tc.desc: Close the worker thread to stop the worker from receiving messages.
* @tc.author: hanyuqing
*/
it
(
'
worker_parentPortClose_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
let
res
=
0
let
flag
=
false
;
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
}
ss
.
onmessage
=
function
(
e
)
{
res
++
;
res
++
}
ss
.
postMessage
(
"
abc
"
)
...
...
@@ -558,17 +976,23 @@ describe('workerTest', function () {
})
// check onmessageerror is ok
/**
* @tc.name: worker_onmessageerror_test_001
* @tc.desc: The onmessage attribute of the worker specifies the event handler when the worker receives
a message that cannot be serialized. The event handler is executed in the host thread
* @tc.author: hanyuqing
*/
it
(
'
worker_onmessageerror_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
let
res
=
0
let
flag
=
false
;
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
}
ss
.
onmessageerror
=
function
(
e
)
{
res
++
;
res
++
}
ss
.
postMessage
(
"
abc
"
)
...
...
@@ -580,14 +1004,24 @@ describe('workerTest', function () {
})
// check onmessageerror is ok
/**
* @tc.name: worker_onmessageerror_test_002
* @tc.desc: The onmessage attribute of the worker specifies the event handler when the worker receives
a message that cannot be serialized. The event handler is executed in the host thread
* @tc.author: hanyuqing
*/
it
(
'
worker_onmessageerror_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_008.js
"
)
let
res
=
0
let
flag
=
false
;
let
flag
=
false
ss
.
onexit
=
function
()
{
flag
=
true
}
ss
.
onmessageerror
=
function
(
e
)
{
flag
=
true
;
res
++
;
flag
=
true
res
++
}
function
foo
()
{
}
...
...
@@ -595,186 +1029,323 @@ describe('workerTest', function () {
while
(
!
flag
)
{
await
promiseCase
()
}
flag
=
false
ss
.
postMessage
(
"
terminate
"
)
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
()
})
// check new second worker is ok
/**
* @tc.name: worker_new_second_worker_test_001
* @tc.desc: Create a second worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_new_second_worker_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_009.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_009.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
flag
=
true
res
=
e
.
data
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
while
(
!
flag
)
{
console
.
log
(
"
worker:: foo wait
"
)
await
promiseCase
()
;
await
promiseCase
()
}
console
.
log
(
"
worker::
"
+
res
)
expect
(
res
).
assertTrue
();
done
();
expect
(
res
).
assertTrue
()
flag
=
false
ss
.
postMessage
({
type
:
"
terminate
"
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
// check new third worker is ok
/**
* @tc.name: worker_new_second_worker_test_002
* @tc.desc: Create a third worker.
* @tc.author: hanyuqing
*/
it
(
'
worker_new_second_worker_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_012.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_012.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
flag
=
true
res
=
e
.
data
}
ss
.
onerror
=
function
(
ee
)
{
console
.
log
(
"
worker::
"
+
ee
.
message
)
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
;
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
while
(
!
flag
)
{
console
.
log
(
"
worker:: worker_second_worker_postMessage_test_001 wait
"
);
ss
.
postMessage
({
type
:
"
wait
"
});
await
promiseCase
();
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
).
assertTrue
()
flag
=
false
ss
.
postMessage
({
type
:
"
terminate
"
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
).
assertTrue
();
done
();
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
// check second worker postMessage number is ok
/**
* @tc.name: worker_second_worker_postMessage_test_001
* @tc.desc: Check if the postMessage function of the second worker is ok.
* @tc.author: hanyuqing
*/
it
(
'
worker_second_worker_postMessage_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_010.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_010.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
flag
=
true
res
=
e
.
data
}
ss
.
onerror
=
function
(
ee
)
{
console
.
log
(
"
worker::
"
+
ee
.
message
)
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
;
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
while
(
!
flag
)
{
console
.
log
(
"
worker:: worker_second_worker_postMessage_test_001 wait
"
);
ss
.
postMessage
({
type
:
"
wait
"
});
await
promiseCase
();
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
25
)
flag
=
false
ss
.
postMessage
({
type
:
"
terminate
"
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
25
);
done
();
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
// check second worker postMessage string is ok
/**
* @tc.name: worker_second_worker_postMessage_test_002
* @tc.desc: Check if the postMessage function of the second worker is ok.
* @tc.author: hanyuqing
*/
it
(
'
worker_second_worker_postMessage_test_002
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_013.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_013.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
flag
=
true
res
=
e
.
data
}
ss
.
onerror
=
function
(
ee
)
{
console
.
log
(
"
worker::
"
+
ee
.
message
)
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
"
hello world
"
})
;
ss
.
postMessage
({
type
:
"
new
"
,
value
:
"
hello world
"
})
while
(
!
flag
)
{
console
.
log
(
"
worker:: worker_second_worker_postMessage_test_002 wait
"
)
ss
.
postMessage
({
type
:
"
wait
"
});
await
promiseCase
();
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
hello world worker
"
);
done
();
expect
(
res
).
assertEqual
(
"
hello world worker
"
)
flag
=
false
ss
.
postMessage
({
type
:
"
terminate
"
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
// check second worker postMessage array is ok
/**
* @tc.name: worker_second_worker_postMessage_test_003
* @tc.desc: Check if the postMessage function of the second worker is ok.
* @tc.author: hanyuqing
*/
it
(
'
worker_second_worker_postMessage_test_003
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_014.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_014.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
flag
=
true
res
=
e
.
data
}
ss
.
onerror
=
function
(
ee
)
{
console
.
log
(
"
worker::
"
+
ee
.
message
)
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
[
1
,
2
]})
;
ss
.
postMessage
({
type
:
"
new
"
,
value
:
[
1
,
2
]})
while
(
!
flag
)
{
console
.
log
(
"
worker:: worker_second_worker_postMessage_test_003 wait
"
)
ss
.
postMessage
({
type
:
"
wait
"
});
await
promiseCase
();
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
[
0
]).
assertEqual
(
2
);
expect
(
res
[
1
]).
assertEqual
(
2
);
done
();
expect
(
res
[
0
]).
assertEqual
(
2
)
expect
(
res
[
1
]).
assertEqual
(
2
)
flag
=
false
ss
.
postMessage
({
type
:
"
terminate
"
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
done
()
})
// check third worker postMessage is ok
it
(
'
worker_second_worker_postMessage_test_004
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_015.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
/**
* @tc.name: worker_third_worker_postMessage_test_001
* @tc.desc: Check if the postMessage function of the third worker is ok.
* @tc.author: hanyuqing
*/
it
(
'
worker_third_worker_postMessage_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_015.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
res
=
e
.
data
}
ss
.
onerror
=
function
(
ee
)
{
console
.
log
(
"
worker::
"
+
ee
.
message
)
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
10
})
;
ss
.
postMessage
({
type
:
"
new
"
,
value
:
10
})
while
(
!
flag
)
{
console
.
log
(
"
worker:: worker_second_worker_postMessage_test_003 wait
"
)
ss
.
postMessage
({
type
:
"
wait
"
});
await
promiseCase
();
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
16
);
done
();
expect
(
res
).
assertEqual
(
16
)
done
()
})
// check second worker terminate is ok
/**
* @tc.name: worker_second_worker_terminate_test_001
* @tc.desc: Check if the terminate function of the second worker is ok.
* @tc.author: hanyuqing
*/
it
(
'
worker_second_worker_terminate_test_001
'
,
0
,
async
function
(
done
)
{
let
ss
=
new
worker
.
Worker
(
"
workers/worker_011.js
"
);
let
flag
=
false
;
let
res
=
undefined
;
let
ss
=
new
worker
.
Worker
(
"
workers/worker_011.js
"
)
let
flag
=
false
let
res
=
undefined
let
isTerminate
=
false
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
;
res
=
e
.
data
;
ss
.
onexit
=
function
()
{
isTerminate
=
true
}
ss
.
onmessage
=
function
(
e
)
{
flag
=
true
res
=
e
.
data
}
ss
.
onerror
=
function
(
ee
)
{
console
.
log
(
"
worker::
"
+
ee
.
message
)
}
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
;
ss
.
postMessage
({
type
:
"
new
"
,
value
:
12
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
;
await
promiseCase
()
;
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
flag
=
false
;
ss
.
postMessage
({
type
:
"
terminate
"
})
;
flag
=
false
ss
.
postMessage
({
type
:
"
terminate
"
})
while
(
!
flag
)
{
ss
.
postMessage
({
type
:
"
wait
"
})
;
await
promiseCase
()
;
ss
.
postMessage
({
type
:
"
wait
"
})
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
terminate
"
);
done
();
ss
.
terminate
()
while
(
!
isTerminate
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
"
terminate
"
)
done
()
})
})
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录