提交 6a25154a 编写于 作者: D duwenbo

Modify the XTS use case about worker

Describe:Replace the worker use cases of the master branch and delete
the second worker use cases. In the end, disable all worker use case
Signed-off-by: Nduwenbo <duwenbo7@huawei.com>
上级 c70620d2
...@@ -19,7 +19,7 @@ group("compileruntime") { ...@@ -19,7 +19,7 @@ group("compileruntime") {
"process_lib_standard:process_js_test", "process_lib_standard:process_js_test",
"url_lib_standard:url_js_test", "url_lib_standard:url_js_test",
"util_lib_standard:util_js_test", "util_lib_standard:util_js_test",
"worker_lib_standard:worker_js_hap", # "worker_lib_standard:worker_js_hap",
] ]
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
"description": "Configuration for startup worker js api Tests", "description": "Configuration for startup worker js api Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "JSUnitTest",
"test-timeout": "60000", "test-timeout": "800000",
"package": "com.example.workerxts", "package": "com.example.workerxts",
"shell-timeout": "60000" "shell-timeout": "90000"
}, },
"kits": [ "kits": [
{ {
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
] ]
} }
], ],
"visible": true,
"orientation": "unspecified", "orientation": "unspecified",
"name": "com.example.workerxts.MainAbility", "name": "com.example.workerxts.MainAbility",
"icon": "$media:icon", "icon": "$media:icon",
......
...@@ -13,24 +13,16 @@ ...@@ -13,24 +13,16 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
function foo(x) {return x}
var worker = globalThis.requireNapi('worker'); console.info("worker:: new version")
const parentPort = worker.parentPort; parentPort.onclose = function() {
console.info("worker:: new version")
parentPort.onclose = function() {
console.info("worker::worker.js onclose"); console.info("worker::worker.js onclose");
} }
parentPort.onmessage = function(e) { parentPort.onmessage = function(e) {
var data = e.data; var data = e.data;
console.info("worker:: worker thread worker data is " + data.data); console.info("worker:: worker thread worker data is " + data.data);
switch(data.type) { switch(data.type) {
...@@ -51,16 +43,14 @@ ...@@ -51,16 +43,14 @@
console.info("worker:: worker.js receive unknow type"); console.info("worker:: worker.js receive unknow type");
break break
} }
} }
// 反序列错误 // 反序列错误
parentPort.onmessageerror = function() { parentPort.onmessageerror = function() {
console.info("worker:: worker.js onmessageerror"); console.info("worker:: worker.js onmessageerror");
} }
// js执行异常 // js执行异常
parentPort.onerror = function(data) { parentPort.onerror = function(data) {
console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno);
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,20 +13,11 @@ ...@@ -13,20 +13,11 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
console.log("worker:: run script");
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
console.log("worker:: worker receive data " + e.data); console.log("worker:: worker receive data " + e.data);
var data = e.data + " worker"; var data = e.data + " worker";
parentPort.postMessage(data) parentPort.postMessage(data)
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,18 +13,10 @@ ...@@ -13,18 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
var data = e.data * 2 + 1 var data = e.data * 2 + 1
parentPort.postMessage(data) parentPort.postMessage(data)
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,19 +13,11 @@ ...@@ -13,19 +13,11 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
var data = e.data; var data = e.data;
data.message = "hello world " + "worker" data.message = "hello world " + "worker"
parentPort.postMessage(data) parentPort.postMessage(data)
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,17 +13,9 @@ ...@@ -13,17 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
parentPort.postMessage(name) parentPort.postMessage(name)
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,17 +13,9 @@ ...@@ -13,17 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
parentPort.postMessage("hello world") parentPort.postMessage("hello world")
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,17 +13,9 @@ ...@@ -13,17 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
throw new Error(123) throw new Error(123)
} }
/******/ })() \ No newline at end of file
;
\ No newline at end of file
...@@ -13,17 +13,9 @@ ...@@ -13,17 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
/******/ (() => { // webpackBootstrap import worker from '@ohos.worker';
var __webpack_exports__ = {}; const parentPort = worker.parentPort;
/*!********************************************************************************************!*\
!*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***!
\********************************************************************************************/
var worker = globalThis.requireNapi('worker');
const parentPort = worker.parentPort; parentPort.onmessage = function(e) {
parentPort.onmessage = function(e) {
parentPort.close() parentPort.close()
} }
/******/ })()
;
\ No newline at end of file
/*
* Copyright (C) 2021 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 app from '@system.app'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('appInfoTest', function () {
it('app_info_test_001', 0, function () {
var info = app.getInfo()
expect(info.versionName).assertEqual('1.0.0')
expect(info.versionCode).assertEqual('1000000')
})
})
\ No newline at end of file
...@@ -13,5 +13,4 @@ ...@@ -13,5 +13,4 @@
* limitations under the License. * limitations under the License.
*/ */
require('./ExampleJsunit.test.js')
require("./Worker.test.js") require("./Worker.test.js")
\ No newline at end of file
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// @ts-nocheck // @ts-nocheck
import app from '@system.app' import app from '@system.app'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import worker from '@ohos.worker' import worker from "@ohos.worker";
describe('workerTest', function () { describe('workerTest', function () {
...@@ -145,7 +145,22 @@ describe('workerTest', function () { ...@@ -145,7 +145,22 @@ describe('workerTest', function () {
const buffer = new ArrayBuffer(8) const buffer = new ArrayBuffer(8)
expect(buffer.byteLength).assertEqual(8) expect(buffer.byteLength).assertEqual(8)
ss.postMessage(buffer, [buffer]) ss.postMessage(buffer, [buffer])
expect(buffer.byteLength).assertEqual(0) var length = undefined;
var exception = undefined;
try {
length = buffer.byteLength;
} catch (e) {
exception = e.message;
}
console.log("worker:: length is " + length)
console.log("worker:: exception is " + exception)
if (typeof exception == "undefined") {
expect(length).assertEqual(0)
} else {
expect(exception).assertEqual("IsDetachedBuffer")
}
}) })
// check worker handle error is ok // check worker handle error is ok
...@@ -463,6 +478,7 @@ describe('workerTest', function () { ...@@ -463,6 +478,7 @@ describe('workerTest', function () {
ss.dispatchEvent({type: "zhangsan"}) ss.dispatchEvent({type: "zhangsan"})
expect(zhangsanTimes).assertEqual(2) expect(zhangsanTimes).assertEqual(2)
}) })
// check worker removeAllListener function is ok // check worker removeAllListener function is ok
...@@ -501,65 +517,23 @@ describe('workerTest', function () { ...@@ -501,65 +517,23 @@ describe('workerTest', function () {
it('worker_parentPortClose_test_001', 0, async function (done) { it('worker_parentPortClose_test_001', 0, async function (done) {
var ss = new worker.Worker("workers/worker_008.js"); var ss = new worker.Worker("workers/worker_008.js");
var res = 0 var res = 0
var flag = false;
ss.onmessage = function (e) { ss.onexit = function (e) {
res++; res++;
flag = true;
} }
ss.postMessage("abc") ss.postMessage("abc")
while (!flag) {
await promiseCase() await promiseCase()
expect(res).assertEqual(0)
done()
})
// check parentPort.close is ok
it('worker_parentPortClose_test_002', 0, async function (done) {
var ss1 = new worker.Worker("workers/worker_008.js");
var ss2 = new worker.Worker("workers/worker_008.js");
var res = 0
var times = 0
ss1.onmessage = function (e) {
res++;
} }
expect(res).assertEqual(1)
ss1.postMessage("abc")
await promiseCase()
expect(res).assertEqual(0)
ss2.postMessage("hello world")
await promiseCase()
expect(res).assertEqual(0)
done()
})
// check parentPort.close is ok
it('worker_parentPortClose_test_003', 0, async function (done) {
var ss1 = new worker.Worker("workers/worker_008.js");
var ss2 = new worker.Worker("workers/worker_008.js");
var res = 0
var times = 0
ss1.onmessage = function (e) {
res++;
}
ss1.postMessage("abc")
await promiseCase()
expect(res).assertEqual(0)
ss2.addEventListener("zhangsan", ()=>{
times++;
})
ss2.dispatchEvent({type: "zhangsan"})
expect(times).assertEqual(1)
done() done()
}) })
// check parentPort.close is ok // check parentPort.close is ok
it('worker_parentPortClose_test_004', 0, async function (done) { it('worker_parentPortClose_test_002', 0, async function (done) {
var ss = new worker.Worker("workers/worker_008.js"); var ss = new worker.Worker("workers/worker_008.js");
var res = 0 var res = 0
var flag = false; var flag = false;
...@@ -605,23 +579,4 @@ describe('workerTest', function () { ...@@ -605,23 +579,4 @@ describe('workerTest', function () {
done() done()
}) })
// check onmessageerror is ok
it('worker_onmessageerror_test_002', 0, async function (done) {
var ss = new worker.Worker("workers/worker_008.js");
var res = 0
var flag = false;
ss.onmessageerror = function (e) {
flag = true;
res++;
}
function foo() {
}
ss.postMessage(foo)
while (!flag) {
await promiseCase()
}
expect(res).assertEqual(1)
done()
})
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册