未验证 提交 da87972b 编写于 作者: O openharmony_ci 提交者: Gitee

!3592 完善Worker模块的测试用例

Merge pull request !3592 from hyq5234/master
......@@ -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;
......
......@@ -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
......@@ -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:
......
......@@ -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:
......
......@@ -1015,6 +1015,10 @@ describe('workerTest', function () {
let res = 0
let flag = false
ss.onexit = function() {
flag = true
}
ss.onmessageerror = function (e) {
flag = true
res++
......@@ -1025,6 +1029,12 @@ describe('workerTest', function () {
while (!flag) {
await promiseCase()
}
flag = false
ss.postMessage("terminate")
while (!flag) {
await promiseCase()
}
expect(res).assertEqual(1)
done()
})
......@@ -1264,12 +1274,15 @@ describe('workerTest', function () {
let ss = new worker.Worker("workers/worker_015.js")
let flag = false
let res = undefined
let isTerminate = false
ss.onmessage = function (e) {
ss.onexit = function() {
isTerminate = true
}
ss.onmessage = function(e) {
flag = true
res = e.data
}
ss.onerror = function(ee) {
console.log("worker:: " + ee.message)
}
......@@ -1279,6 +1292,11 @@ describe('workerTest', function () {
ss.postMessage({type: "wait"})
await promiseCase()
}
ss.terminate()
while (!isTerminate) {
await promiseCase()
}
expect(res).assertEqual(16)
done()
......@@ -1294,8 +1312,13 @@ describe('workerTest', function () {
let ss = new worker.Worker("workers/worker_011.js")
let flag = false
let res = undefined
let isTerminate = false
ss.onmessage = function (e) {
ss.onexit = function() {
isTerminate = true
}
ss.onmessage = function(e) {
flag = true
res = e.data
}
......@@ -1317,6 +1340,11 @@ describe('workerTest', function () {
await promiseCase()
}
ss.terminate()
while (!isTerminate) {
await promiseCase()
}
expect(res).assertEqual("terminate")
done()
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册