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

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

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