提交 b84494b7 编写于 作者: B buzhuyu

modify and add taskpool xts

description:
1.modify taskpool.cancel xts test
2.add taskGroup xts test
3.add setTransferList xts test

issue:https://gitee.com/openharmony/xts_acts/issues/I7F07TSigned-off-by: Nbuzhuyu <buzhuyu@huawei.com>
上级 cb8a2d62
......@@ -29,17 +29,89 @@ describe('ActsAbilityTest', function () {
return p
}
it('TaskPoolTestClass001', 0, async function (done) {
/**
* @tc.number : TaskPoolTestClass001
* @tc.name : Async Function use taskpool and worker
* @tc.desc : Test Simultaneous use taskpool and worker
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass001', 0, async function (done) {
function testTaskPool() {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
let start = new Date().getTime();
while (new Date().getTime() - start < 3000) {
continue;
}
return arg + 1;
}
try {
let task1 = new taskpool.Task(additionDelay, 100);
let task2 = new taskpool.Task(additionDelay, 200);
let task3 = new taskpool.Task(addition, 300);
taskpool.execute(task1)
taskpool.execute(task2)
taskpool.execute(task3)
let start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
for (let i = 1; i <= 10; i++) {
taskpool.cancel(task1);
}
}
catch (e) {
console.info("taskpoolXTS061 catch error: " + e);
}
}
function promiseCase() {
let p = new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(0)
}, 100)
}).then(undefined, (error) => {
})
return p
}
let ss = new worker.ThreadWorker("entry/ets/workers/worker.js")
let res = 0
let flag = false
ss.onexit = function () {
flag = true
res++
}
testTaskPool();
for (let i = 0; i < 10; i++) {
ss.terminate();
}
while (!flag) {
await promiseCase()
}
expect(res).assertEqual(1)
done();
})
it('TaskPoolTestClass002', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result = await taskpool.execute(Sum, 10, 20);
let result = await taskpool.execute(Sum, 10, 20);
expect(result).assertEqual(30);
done();
})
it('TaskPoolTestClass002', 0, async function (done) {
it('TaskPoolTestClass003', 0, async function (done) {
function Add(value1, value2) {
"use concurrent"
if (value1 & value2)
......@@ -47,33 +119,33 @@ describe('ActsAbilityTest', function () {
else
return false;
}
var result = await taskpool.execute(Add, true, true);
let result = await taskpool.execute(Add, true, true);
expect(result).assertEqual(true);
done();
})
it('TaskPoolTestClass003', 0, async function (done) {
it('TaskPoolTestClass004', 0, async function (done) {
function StrCat(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result = await taskpool.execute(StrCat, "abc", "def");
let result = await taskpool.execute(StrCat, "abc", "def");
expect(result).assertEqual("abcdef");
done();
})
it('TaskPoolTestClass004', 0, async function (done) {
it('TaskPoolTestClass005', 0, async function (done) {
function StrCat(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result = await taskpool.execute(StrCat, "abc", "def");
let result = await taskpool.execute(StrCat, "abc", "def");
result = await taskpool.execute(StrCat, "abc", "def");
expect(result).assertEqual("abcdef");
done();
})
it('TaskPoolTestClass005', 0, async function (done) {
it('TaskPoolTestClass006', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
function StrCat(value1, value2) {
......@@ -81,12 +153,12 @@ describe('ActsAbilityTest', function () {
}
return value1+StrCat(value2,"hello");
}
var result = await taskpool.execute(Sum, "abc", "def");
let result = await taskpool.execute(Sum, "abc", "def");
expect(result).assertEqual("abcdefhello");
done();
})
it('TaskPoolTestClass006', 0, async function (done) {
it('TaskPoolTestClass007', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = [];
......@@ -94,13 +166,13 @@ describe('ActsAbilityTest', function () {
value[1] = arg1[1] + arg2[1];
return value;
}
var result = await taskpool.execute(Sum, [1,2], [3,4]);
let result = await taskpool.execute(Sum, [1,2], [3,4]);
expect(result[0]).assertEqual(4);
expect(result[1]).assertEqual(6);
done();
})
it('TaskPoolTestClass007', 0, async function (done) {
it('TaskPoolTestClass008', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = arg1;
......@@ -108,56 +180,56 @@ describe('ActsAbilityTest', function () {
value.b = arg1.b + arg2.b;
return value;
}
var result = await taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
let result = await taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}");
done();
})
it('TaskPoolTestClass008', 0, async function (done) {
it('TaskPoolTestClass009', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result = await taskpool.execute(Sum, 10);
let result = await taskpool.execute(Sum, 10);
expect(result.toString()).assertEqual("NaN");
done();
})
it('TaskPoolTestClass009', 0, async function (done) {
it('TaskPoolTestClass010', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result = await taskpool.execute(Sum, 10, 20, 30);
let result = await taskpool.execute(Sum, 10, 20, 30);
expect(result).assertEqual(30);
done();
})
it('TaskPoolTestClass010', 0, async function (done) {
it('TaskPoolTestClass011', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1 = await taskpool.execute(Sum, 10, 20);
var result2 = await taskpool.execute(Sum, 30, 40);
let result1 = await taskpool.execute(Sum, 10, 20);
let result2 = await taskpool.execute(Sum, 30, 40);
expect(result1).assertEqual(30);
expect(result2).assertEqual(70);
done();
})
it('TaskPoolTestClass011', 0, async function (done) {
it('TaskPoolTestClass012', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1 = await taskpool.execute(Sum, 10, 20);
var result2 = await taskpool.execute(Sum, 10, 20);
let result1 = await taskpool.execute(Sum, 10, 20);
let result2 = await taskpool.execute(Sum, 10, 20);
expect(result1).assertEqual(30);
expect(result2).assertEqual(30);
done();
})
it('TaskPoolTestClass012', 0, async function (done) {
it('TaskPoolTestClass013', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
......@@ -166,10 +238,10 @@ describe('ActsAbilityTest', function () {
"use concurrent"
return value1 * value2;
}
var result1 = await taskpool.execute(Sum, 10, 20);
var result2 = await taskpool.execute(Multi, 10, 20);
var result3 = await taskpool.execute(Sum, 10, 30);
var result4 = await taskpool.execute(Multi, 20, 20);
let result1 = await taskpool.execute(Sum, 10, 20);
let result2 = await taskpool.execute(Multi, 10, 20);
let result3 = await taskpool.execute(Sum, 10, 30);
let result4 = await taskpool.execute(Multi, 20, 20);
expect(result1).assertEqual(30);
expect(result2).assertEqual(200);
expect(result3).assertEqual(40);
......@@ -177,18 +249,18 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass013', 0, async function (done) {
it('TaskPoolTestClass014', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(Sum, 10, 20);
var result = await taskpool.execute(task);
let task = new taskpool.Task(Sum, 10, 20);
let result = await taskpool.execute(task);
expect(result).assertEqual(30);
done();
})
it('TaskPoolTestClass014', 0, async function (done) {
it('TaskPoolTestClass015', 0, async function (done) {
function Add(value1, value2) {
"use concurrent"
if (value1 & value2)
......@@ -196,24 +268,24 @@ describe('ActsAbilityTest', function () {
else
return false;
}
var task = new taskpool.Task(Add, true, true);
var result = await taskpool.execute(task);
let task = new taskpool.Task(Add, true, true);
let result = await taskpool.execute(task);
expect(result).assertEqual(true);
done();
})
it('TaskPoolTestClass015', 0, async function (done) {
it('TaskPoolTestClass016', 0, async function (done) {
function StrCat(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(StrCat, "abc", "def");
var result = await taskpool.execute(task);
let task = new taskpool.Task(StrCat, "abc", "def");
let result = await taskpool.execute(task);
expect(result).assertEqual("abcdef");
done();
})
it('TaskPoolTestClass016', 0, async function (done) {
it('TaskPoolTestClass017', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
function StrCat(value1, value2) {
......@@ -221,13 +293,13 @@ describe('ActsAbilityTest', function () {
}
return value1+StrCat(value2,"hello");
}
var task = new taskpool.Task(Sum, "abc", "def");
var result = await taskpool.execute(task);
let task = new taskpool.Task(Sum, "abc", "def");
let result = await taskpool.execute(task);
expect(result).assertEqual("abcdefhello");
done();
})
it('TaskPoolTestClass017', 0, async function (done) {
it('TaskPoolTestClass018', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = [];
......@@ -235,14 +307,14 @@ describe('ActsAbilityTest', function () {
value[1] = arg1[1] + arg2[1];
return value;
}
var task = new taskpool.Task(Sum, [1,2], [3,4]);
var result = await taskpool.execute(task);
let task = new taskpool.Task(Sum, [1,2], [3,4]);
let result = await taskpool.execute(task);
expect(result[0]).assertEqual(4);
expect(result[1]).assertEqual(6);
done();
})
it('TaskPoolTestClass018', 0, async function (done) {
it('TaskPoolTestClass019', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = arg1;
......@@ -250,76 +322,76 @@ describe('ActsAbilityTest', function () {
value.b = arg1.b + arg2.b;
return value;
}
var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
var result = await taskpool.execute(task);
let task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
let result = await taskpool.execute(task);
expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}");
done();
})
it('TaskPoolTestClass019', 0, async function (done) {
it('TaskPoolTestClass020', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(Sum, 10);
var result = await taskpool.execute(task);
let task = new taskpool.Task(Sum, 10);
let result = await taskpool.execute(task);
expect(result.toString()).assertEqual("NaN");
done();
})
it('TaskPoolTestClass020', 0, async function (done) {
it('TaskPoolTestClass021', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(Sum, 10, 20, 30);
var result = await taskpool.execute(task);
let task = new taskpool.Task(Sum, 10, 20, 30);
let result = await taskpool.execute(task);
expect(result).assertEqual(30);
done();
})
it('TaskPoolTestClass021', 0, async function (done) {
it('TaskPoolTestClass022', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(Sum, 10, 20);
var result1 = await taskpool.execute(task);
var result2 = await taskpool.execute(task);
let task = new taskpool.Task(Sum, 10, 20);
let result1 = await taskpool.execute(task);
let result2 = await taskpool.execute(task);
expect(result1).assertEqual(30);
expect(result2).assertEqual(30);
done();
})
it('TaskPoolTestClass022', 0, async function (done) {
it('TaskPoolTestClass023', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task1 = new taskpool.Task(Sum, 10, 20);
var task2 = new taskpool.Task(Sum, 30, 40);
var result1 = await taskpool.execute(task1);
var result2 = await taskpool.execute(task2);
let task1 = new taskpool.Task(Sum, 10, 20);
let task2 = new taskpool.Task(Sum, 30, 40);
let result1 = await taskpool.execute(task1);
let result2 = await taskpool.execute(task2);
expect(result1).assertEqual(30);
expect(result2).assertEqual(70);
done();
})
it('TaskPoolTestClass023', 0, async function (done) {
it('TaskPoolTestClass024', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task1 = new taskpool.Task(Sum, 10, 20);
var task2 = new taskpool.Task(Sum, 10, 20);
var result1 = await taskpool.execute(task1);
var result2 = await taskpool.execute(task2);
let task1 = new taskpool.Task(Sum, 10, 20);
let task2 = new taskpool.Task(Sum, 10, 20);
let result1 = await taskpool.execute(task1);
let result2 = await taskpool.execute(task2);
expect(result1).assertEqual(30);
expect(result2).assertEqual(30);
done();
})
it('TaskPoolTestClass024', 0, async function (done) {
it('TaskPoolTestClass025', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
......@@ -328,14 +400,14 @@ describe('ActsAbilityTest', function () {
"use concurrent"
return value1 * value2;
}
var task1 = new taskpool.Task(Sum, 10, 20);
var result1 = await taskpool.execute(task1);
var task2 = new taskpool.Task(Multi, 10, 20);
var result2 = await taskpool.execute(task2);
var task3 = new taskpool.Task(Sum, 10, 30);
var result3 = await taskpool.execute(task3);
var task4 = new taskpool.Task(Multi, 20, 20);
var result4 = await taskpool.execute(task4);
let task1 = new taskpool.Task(Sum, 10, 20);
let result1 = await taskpool.execute(task1);
let task2 = new taskpool.Task(Multi, 10, 20);
let result2 = await taskpool.execute(task2);
let task3 = new taskpool.Task(Sum, 10, 30);
let result3 = await taskpool.execute(task3);
let task4 = new taskpool.Task(Multi, 20, 20);
let result4 = await taskpool.execute(task4);
expect(result1).assertEqual(30);
expect(result2).assertEqual(200);
expect(result3).assertEqual(40);
......@@ -343,14 +415,14 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass025', 0, async function (done) {
it('TaskPoolTestClass026', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result;
var isTerminate = false;
var task = new taskpool.Task(Sum, 10, 20)
let result;
let isTerminate = false;
let task = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -362,7 +434,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass026', 0, async function (done) {
it('TaskPoolTestClass027', 0, async function (done) {
function Add(value1, value2) {
"use concurrent"
if (value1 & value2)
......@@ -370,9 +442,9 @@ describe('ActsAbilityTest', function () {
else
return false;
}
var task = new taskpool.Task(Add, true, true)
var result;
var isTerminate = false;
let task = new taskpool.Task(Add, true, true)
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -384,14 +456,14 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass027', 0, async function (done) {
it('TaskPoolTestClass028', 0, async function (done) {
function StrCat(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(StrCat, "abc", "def")
var result;
var isTerminate = false;
let task = new taskpool.Task(StrCat, "abc", "def")
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -403,7 +475,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass028', 0, async function (done) {
it('TaskPoolTestClass029', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
function StrCat(value1, value2) {
......@@ -411,9 +483,9 @@ describe('ActsAbilityTest', function () {
}
return value1+StrCat(value2,"hello");
}
var task = new taskpool.Task(Sum, "abc", "def");
var result;
var isTerminate = false;
let task = new taskpool.Task(Sum, "abc", "def");
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -425,7 +497,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass029', 0, async function (done) {
it('TaskPoolTestClass030', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = [];
......@@ -433,9 +505,9 @@ describe('ActsAbilityTest', function () {
value[1] = arg1[1] + arg2[1];
return value;
}
var task = new taskpool.Task(Sum, [1,2], [3,4]);
var result;
var isTerminate = false;
let task = new taskpool.Task(Sum, [1,2], [3,4]);
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -448,7 +520,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass030', 0, async function (done) {
it('TaskPoolTestClass031', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = arg1;
......@@ -456,9 +528,9 @@ describe('ActsAbilityTest', function () {
value.b = arg1.b + arg2.b;
return value;
}
var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
var result;
var isTerminate = false;
let task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -470,14 +542,14 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass031', 0, async function (done) {
it('TaskPoolTestClass032', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(Sum, 10);
var result;
var isTerminate = false;
let task = new taskpool.Task(Sum, 10);
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -489,14 +561,14 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass032', 0, async function (done) {
it('TaskPoolTestClass033', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var task = new taskpool.Task(Sum, 10, 20, 30);
var result;
var isTerminate = false;
let task = new taskpool.Task(Sum, 10, 20, 30);
let result;
let isTerminate = false;
taskpool.execute(task).then((ret) => {
result = ret;
isTerminate = true;
......@@ -508,23 +580,23 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass033', 0, async function (done) {
it('TaskPoolTestClass034', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
let result1;
let result2;
let isTerminate1 = false;
let isTerminate2 = false;
var task1 = new taskpool.Task(Sum, 10, 20);
let task1 = new taskpool.Task(Sum, 10, 20);
taskpool.execute(task1).then((ret1) => {
result1 = ret1;
isTerminate1 = true;
})
var task2 = new taskpool.Task(Sum, 30, 40);
let task2 = new taskpool.Task(Sum, 30, 40);
taskpool.execute(task2).then((ret2) => {
result2 = ret2;
isTerminate2 = true;
......@@ -537,22 +609,22 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass034', 0, async function (done) {
it('TaskPoolTestClass035', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
let result1;
let result2;
let isTerminate1 = false;
let isTerminate2 = false;
var task1 = new taskpool.Task(Sum, 10, 20)
let task1 = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task1).then((ret1) => {
result1 = ret1;
isTerminate1 = true;
})
var task2 = new taskpool.Task(Sum, 10, 20)
let task2 = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task2).then((ret2) => {
result2 = ret2;
isTerminate2 = true;
......@@ -565,17 +637,17 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass035', 0, async function (done) {
it('TaskPoolTestClass036', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
let result1;
let result2;
let isTerminate1 = false;
let isTerminate2 = false;
var task = new taskpool.Task(Sum, 10, 20)
let task = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task).then((ret1) => {
result1 = ret1;
isTerminate1 = true;
......@@ -592,7 +664,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass036', 0, async function (done) {
it('TaskPoolTestClass037', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
......@@ -602,31 +674,31 @@ describe('ActsAbilityTest', function () {
return value1 * value2;
}
var result1;
var result2;
var result3;
var result4;
var isTerminate1 = false;
var isTerminate2 = false;
var isTerminate3 = false;
var isTerminate4 = false;
let result1;
let result2;
let result3;
let result4;
let isTerminate1 = false;
let isTerminate2 = false;
let isTerminate3 = false;
let isTerminate4 = false;
var task1 = new taskpool.Task(Sum, 10, 20)
let task1 = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task1).then((ret1) => {
result1 = ret1;
isTerminate1 = true;
})
var task2 = new taskpool.Task(Multi, 10, 20)
let task2 = new taskpool.Task(Multi, 10, 20)
taskpool.execute(task2).then((ret2) => {
result2 = ret2;
isTerminate2 = true;
})
var task3 = new taskpool.Task(Sum, 10, 30)
let task3 = new taskpool.Task(Sum, 10, 30)
taskpool.execute(task3).then((ret3) => {
result3 = ret3;
isTerminate3 = true;
})
var task4 = new taskpool.Task(Multi, 20, 20)
let task4 = new taskpool.Task(Multi, 20, 20)
taskpool.execute(task4).then((ret4) => {
result4 = ret4;
isTerminate4 = true;
......@@ -642,13 +714,13 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass037', 0, async function (done) {
it('TaskPoolTestClass038', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Sum, 10, 20).then((ret) => {
result = ret;
isTerminate = true;
......@@ -660,7 +732,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass038', 0, async function (done) {
it('TaskPoolTestClass039', 0, async function (done) {
function Add(value1, value2) {
"use concurrent"
if (value1 & value2)
......@@ -668,8 +740,8 @@ describe('ActsAbilityTest', function () {
else
return false;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Add, true, false).then((ret) => {
result = ret;
isTerminate = true;
......@@ -681,13 +753,13 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass039', 0, async function (done) {
it('TaskPoolTestClass040', 0, async function (done) {
function StrCat(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(StrCat, "abc", "def").then((ret) => {
result = ret;
isTerminate = true;
......@@ -699,7 +771,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass040', 0, async function (done) {
it('TaskPoolTestClass041', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
function StrCat(value1, value2) {
......@@ -707,8 +779,8 @@ describe('ActsAbilityTest', function () {
}
return value1+StrCat(value2,"hello");
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Sum, "abc", "def").then((ret) => {
result = ret;
isTerminate = true;
......@@ -720,7 +792,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass041', 0, async function (done) {
it('TaskPoolTestClass042', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = [];
......@@ -728,8 +800,8 @@ describe('ActsAbilityTest', function () {
value[1] = arg1[1] + arg2[1];
return value;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Sum, [1,2], [3,4]).then((ret) => {
result = ret;
isTerminate = true;
......@@ -742,7 +814,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass042', 0, async function (done) {
it('TaskPoolTestClass043', 0, async function (done) {
function Sum(arg1, arg2) {
"use concurrent"
let value = arg1;
......@@ -750,8 +822,8 @@ describe('ActsAbilityTest', function () {
value.b = arg1.b + arg2.b;
return value;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}).then((ret) => {
result = ret;
isTerminate = true;
......@@ -763,13 +835,13 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass043', 0, async function (done) {
it('TaskPoolTestClass044', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Sum, 10).then((ret) => {
result = ret;
isTerminate = true;
......@@ -781,13 +853,13 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass044', 0, async function (done) {
it('TaskPoolTestClass045', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result;
var isTerminate = false;
let result;
let isTerminate = false;
taskpool.execute(Sum, 10, 20, 30).then((ret) => {
result = ret;
isTerminate = true;
......@@ -799,15 +871,15 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass045', 0, async function (done) {
it('TaskPoolTestClass046', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
let result1;
let result2;
let isTerminate1 = false;
let isTerminate2 = false;
taskpool.execute(Sum, 10, 20).then((ret1) => {
result1 = ret1;
......@@ -825,15 +897,15 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass046', 0, async function (done) {
it('TaskPoolTestClass047', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
let result1;
let result2;
let isTerminate1 = false;
let isTerminate2 = false;
taskpool.execute(Sum, 10, 20).then((ret1) => {
result1 = ret1;
......@@ -851,7 +923,7 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass047', 0, async function (done) {
it('TaskPoolTestClass048', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
......@@ -861,14 +933,14 @@ describe('ActsAbilityTest', function () {
return value1 * value2;
}
var result1;
var result2;
var result3;
var result4;
var isTerminate1 = false;
var isTerminate2 = false;
var isTerminate3 = false;
var isTerminate4 = false;
let result1;
let result2;
let result3;
let result4;
let isTerminate1 = false;
let isTerminate2 = false;
let isTerminate3 = false;
let isTerminate4 = false;
taskpool.execute(Sum, 10, 20).then((ret1) => {
result1 = ret1;
......@@ -896,13 +968,13 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass048', 0, async function (done) {
it('TaskPoolTestClass049', 0, async function (done) {
function Sum(value1, value2) {
"use concurrent"
return value1 + value2;
}
try {
var result = await taskpool.execute(Sum);
let result = await taskpool.execute(Sum);
} catch(e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: first param must be object when argc is one");
}
......@@ -910,14 +982,14 @@ describe('ActsAbilityTest', function () {
})
/**
* @tc.number : TaskPoolTestClass061
* @tc.number : TaskPoolTestClass049
* @tc.name : Async Function about priority task
* @tc.desc : Execute priority tasks
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass061', 0, async function (done) {
it('TaskPoolTestClass050', 0, async function (done) {
function testTime() {
"use concurrent";
return Date.now();
......@@ -963,7 +1035,15 @@ describe('ActsAbilityTest', function () {
done();
})
it('TaskPoolTestClass062', 0, async function (done) {
/**
* @tc.number : TaskPoolTestClass051
* @tc.name : Async function execute task
* @tc.desc : Execute async function
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass051', 0, async function (done) {
async function func(value1, value2) {
"use concurrent"
let result = await new Promise((resolve, reject) => {
......@@ -972,12 +1052,20 @@ describe('ActsAbilityTest', function () {
})
return result;
}
var result = await taskpool.execute(func, 10, 20);
let result = await taskpool.execute(func, 10, 20);
expect(result).assertEqual(30);
done();
})
it('TaskPoolTestClass063', 0, async function (done) {
/**
* @tc.number : TaskPoolTestClass052
* @tc.name : Async function execute task
* @tc.desc : Execute async function task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass052', 0, async function (done) {
async function func(value1, value2) {
"use concurrent"
let result = await new Promise((resolve, reject) => {
......@@ -986,318 +1074,181 @@ describe('ActsAbilityTest', function () {
})
return result;
}
var task = new taskpool.Task(func, 10, 20);
var result = await taskpool.execute(task);
let task = new taskpool.Task(func, 10, 20);
let result = await taskpool.execute(task);
expect(result).assertEqual(30);
done();
})
/**
* @tc.number : TaskPoolTestClass049
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel tasks that have not been executed
* @tc.number : TaskPoolTestClass053
* @tc.name : Async function execute taskGroup
* @tc.desc : Execute async function
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass049', 0, async function (done) {
function addition(arg) {
it('TaskPoolTestClass053', 0, async function (done) {
function printArgs(args) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
var start = new Date().getTime();
while (new Date().getTime() - start < 200) {
continue;
}
return arg + 1;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(additionDelay, 200);
var task4 = new taskpool.Task(additionDelay, 200);
var task5 = new taskpool.Task(additionDelay, 200);
var task6 = new taskpool.Task(additionDelay, 200);
var task7 = new taskpool.Task(additionDelay, 200);
var task8 = new taskpool.Task(additionDelay, 200);
var task9 = new taskpool.Task(additionDelay, 200);
var task10 = new taskpool.Task(additionDelay, 200);
var task11 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6);
var result7 = taskpool.execute(task7);
var result8 = taskpool.execute(task8);
var result9 = taskpool.execute(task9);
var result10 = taskpool.execute(task10);
var result11 = taskpool.execute(task11);
var start = new Date().getTime();
while (new Date().getTime() - start < 20) {
continue;
}
taskpool.cancel(task11);
return args;
}
catch (e) {
expect(e.toString()).assertEqual("");
}
done();
})
/**
* @tc.number : TaskPoolTestClass050
* @tc.name : Sync Function Cancel task
* @tc.desc : Cancel tasks that have not been executed
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass050', 0, function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
var start = new Date().getTime();
while (new Date().getTime() - start < 200) {
continue;
}
return arg + 1;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(additionDelay, 200);
var task4 = new taskpool.Task(additionDelay, 200);
var task5 = new taskpool.Task(additionDelay, 200);
var task6 = new taskpool.Task(additionDelay, 200);
var task7 = new taskpool.Task(additionDelay, 200);
var task8 = new taskpool.Task(additionDelay, 200);
var task9 = new taskpool.Task(additionDelay, 200);
var task10 = new taskpool.Task(additionDelay, 200);
var task11 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6);
var result7 = taskpool.execute(task7);
var result8 = taskpool.execute(task8);
var result9 = taskpool.execute(task9);
var result10 = taskpool.execute(task10);
var result11 = taskpool.execute(task11);
var start = new Date().getTime();
while (new Date().getTime() - start < 20) {
continue;
}
let taskGroup = new taskpool.TaskGroup();
taskGroup.addTask(printArgs, 10);
taskGroup.addTask(printArgs, 20);
taskGroup.addTask(printArgs, 30);
taskpool.cancel(task11);
}
catch (e) {
expect(e.toString()).assertEqual("");
}
taskpool.execute(taskGroup).then((res) => {
expect(res[0]).assertEqual(10);
expect(res[1]).assertEqual(20);
expect(res[2]).assertEqual(30);
});
done();
})
/**
* @tc.number : TaskPoolTestClass051
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel the task in progress
* @tc.number : TaskPoolTestClass054
* @tc.name : Async function execute taskGroup
* @tc.desc : Execute async function
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass051', 0, async function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
it('TaskPoolTestClass054', 0, async function (done) {
function printArgs(args) {
"use concurrent"
var start = new Date().getTime();
while (new Date().getTime() - start < 3000) {
continue;
}
return arg + 1;
return args;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
taskpool.cancel(task1);
}
catch (e) {
expect(e.toString()).assertEqual(
"BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task");
}
let taskGroup = new taskpool.TaskGroup();
let task1 = new taskpool.Task(printArgs, 100);
let task2 = new taskpool.Task(printArgs, 200);
let task3 = new taskpool.Task(printArgs, 300);
taskGroup.addTask(task1);
taskGroup.addTask(task2);
taskGroup.addTask(task3);
taskpool.execute(taskGroup).then((res) => {
expect(res[0]).assertEqual(10);
expect(res[1]).assertEqual(20);
expect(res[2]).assertEqual(30);
});
done();
})
/**
* @tc.number : TaskPoolTestClass052
* @tc.name : Sync Function Cancel task
* @tc.desc : Cancel the task in progress
* @tc.number : TaskPoolTestClass055
* @tc.name : SetTransferList for task
* @tc.desc : Set transfer list for the task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass052', 0, function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
var start = new Date().getTime();
while (new Date().getTime() - start < 3000) {
continue;
}
return arg + 1;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
it('TaskPoolTestClass055', 0, async function (done) {
let buffer = new ArrayBuffer(8);
let view = new Uint8Array(buffer);
let buffer1 = new ArrayBuffer(16);
let view1 = new Uint8Array(buffer1);
var start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
taskpool.cancel(task1);
}
catch (e) {
expect(e.toString()).assertEqual(
"BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task");
function testTransfer(arg1, arg2) {
"use concurrent"
return arg1.byteLength + arg2.byteLength;
}
let task = new taskpool.Task(testTransfer, view, view1);
task.setTransferList([view.buffer, view1.buffer]);
taskpool.execute(task).then((res)=>{
expect(res).assertEqual(24);
});
done();
})
/**
* @tc.number : TaskPoolTestClass053
* @tc.number : TaskPoolTestClass056
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel the executed task
* @tc.desc : Cancel tasks that have not been executed
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass053', 0, async function (done) {
function addition(arg) {
it('TaskPoolTestClass056', 0, async function (done) {
function inspectStatus(arg) {
"use concurrent"
return arg + 1;
return arg;
}
try {
var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
taskpool.cancel(task1);
}
catch (e) {
expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
}
let task = new taskpool.Task(inspectStatus, 100);
taskpool.execute(task);
taskpool.cancel(task);
expect(taskpool.Task.isCanceled() == false);
done();
})
/**
* @tc.number : TaskPoolTestClass054
* @tc.name : Sync Function Cancel task
* @tc.desc : Cancel the executed task
* @tc.number : TaskPoolTestClass057
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel the task in progress
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass054', 0, function (done) {
function addition(arg) {
it('TaskPoolTestClass057', 0, async function (done) {
function inspectStatus(arg) {
"use concurrent"
return arg + 1;
return arg;
}
try {
var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300);
var task4 = new taskpool.Task(addition, 400);
var task5 = new taskpool.Task(addition, 500);
var task6 = new taskpool.Task(addition, 600);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6);
var start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
taskpool.cancel(task3);
}
catch (e) {
try {
let task1 = new taskpool.Task(inspectStatus, 100);
let task2 = new taskpool.Task(inspectStatus, 200);
let task3 = new taskpool.Task(inspectStatus, 300);
let task4 = new taskpool.Task(inspectStatus, 400);
let task5 = new taskpool.Task(inspectStatus, 500);
let task6 = new taskpool.Task(inspectStatus, 600);
let res1 = taskpool.execute(task1);
let res2 = taskpool.execute(task2);
let res3 = taskpool.execute(task3);
let res4 = taskpool.execute(task4);
let res5 = taskpool.execute(task5);
let res6 = taskpool.execute(task6);
taskpool.execute(task1);
taskpool.cancel(task1);
} catch(e) {
expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
}
expect(taskpool.Task.isCanceled() == false);
done();
})
/**
* @tc.number : TaskPoolTestClass055
* @tc.number : TaskPoolTestClass058
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel nonexistent task
* @tc.desc : Cancel the executed task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass055', 0, async function (done) {
it('TaskPoolTestClass058', 0, async function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
try {
var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300);
let task1 = new taskpool.Task(addition, 100);
let task2 = new taskpool.Task(addition, 200);
let task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
let result1 = taskpool.execute(task1);
let result2 = taskpool.execute(task2);
let result3 = taskpool.execute(task3);
taskpool.cancel(task3);
let start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
taskpool.cancel(task1);
}
catch (e) {
expect(e.toString()).assertEqual(
......@@ -1307,25 +1258,25 @@ describe('ActsAbilityTest', function () {
})
/**
* @tc.number : TaskPoolTestClass056
* @tc.name : Sync Function Cancel task
* @tc.number : TaskPoolTestClass059
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel nonexistent task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass056', 0, function (done) {
it('TaskPoolTestClass059', 0, async function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
try {
var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300);
let task1 = new taskpool.Task(addition, 100);
let task2 = new taskpool.Task(addition, 200);
let task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
let result1 = taskpool.execute(task1);
let result2 = taskpool.execute(task2);
taskpool.cancel(task3);
}
......@@ -1337,36 +1288,36 @@ describe('ActsAbilityTest', function () {
})
/**
* @tc.number : TaskPoolTestClass057
* @tc.number : TaskPoolTestClass060
* @tc.name : Async Function Cancel task
* @tc.desc : Canceling unexecuted tasks multiple times
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass057', 0, async function (done) {
it('TaskPoolTestClass060', 0, async function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
var start = new Date().getTime();
let start = new Date().getTime();
while (new Date().getTime() - start < 3000) {
continue;
}
return arg + 1;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300);
let task1 = new taskpool.Task(additionDelay, 100);
let task2 = new taskpool.Task(additionDelay, 200);
let task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
let result1 = taskpool.execute(task1);
let result2 = taskpool.execute(task2);
let result3 = taskpool.execute(task3);
var start = new Date().getTime();
let start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
......@@ -1382,42 +1333,43 @@ describe('ActsAbilityTest', function () {
})
/**
* @tc.number : TaskPoolTestClass058
* @tc.name : Sync Function Cancel task
* @tc.desc : Canceling unexecuted tasks multiple times
* @tc.number : TaskPoolTestClass061
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel all tasks in sequence
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass058', 0, function (done) {
it('TaskPoolTestClass061', 0, async function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
var start = new Date().getTime();
while (new Date().getTime() - start < 3000) {
continue;
}
return arg + 1;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
let task1 = new taskpool.Task(addition, 100);
let task2 = new taskpool.Task(addition, 200);
let task3 = new taskpool.Task(addition, 300);
let task4 = new taskpool.Task(addition, 400);
let task5 = new taskpool.Task(addition, 500);
let task6 = new taskpool.Task(addition, 600);
let result1 = taskpool.execute(task1);
let result2 = taskpool.execute(task2);
let result3 = taskpool.execute(task3);
let result4 = taskpool.execute(task4);
let result5 = taskpool.execute(task5);
let result6 = taskpool.execute(task6);
let start = new Date().getTime();
while (new Date().getTime() - start < 100) {
continue;
}
taskpool.cancel(task6);
taskpool.cancel(task5);
taskpool.cancel(task4);
taskpool.cancel(task3);
taskpool.cancel(task3);
taskpool.cancel(task2);
}
catch (e) {
expect(e.toString()).assertEqual(
......@@ -1427,168 +1379,145 @@ describe('ActsAbilityTest', function () {
})
/**
* @tc.number : TaskPoolTestClass059
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel all tasks in sequence
* @tc.number : TaskPoolTestClass062
* @tc.name : Async Function Cancel taskGroup
* @tc.desc : Cancel the taskGroup in progress
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass059', 0, async function (done) {
it('TaskPoolTestClass062', 0, async function (done) {
function addition(arg) {
"use concurrent"
return arg + 1;
}
try {
var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300);
var task4 = new taskpool.Task(addition, 400);
var task5 = new taskpool.Task(addition, 500);
var task6 = new taskpool.Task(addition, 600);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6);
var start = new Date().getTime();
while (new Date().getTime() - start < 100) {
let start = new Date().getTime();
while (new Date().getTime() - start < 2000) {
continue;
}
taskpool.cancel(task6);
taskpool.cancel(task5);
taskpool.cancel(task4);
taskpool.cancel(task3);
taskpool.cancel(task2);
}
catch (e) {
expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
return arg + 1;
}
let i = 10;
let taskGroup1 = new taskpool.TaskGroup();
taskGroup1.addTask(addition, 10);
taskGroup1.addTask(addition, 20);
taskGroup1.addTask(addition, 30);
let taskGroup2 = new taskpool.TaskGroup();
let task1 = new taskpool.Task(addition, 100);
let task2 = new taskpool.Task(addition, 200);
let task3 = new taskpool.Task(addition, 300);
taskGroup2.addTask(task1);
taskGroup2.addTask(task2);
taskGroup2.addTask(task3);
taskpool.execute(taskGroup1).then(() => {
++i;
});
taskpool.execute(taskGroup2);
taskpool.cancel(taskGroup1);
expect(i).assertEqual(10)
done();
})
/**
* @tc.number : TaskPoolTestClass060
* @tc.name : Sync Function Cancel task
* @tc.desc : Cancel all tasks in sequence
* @tc.number : TaskPoolTestClass063
* @tc.name : Async Function Cancel taskGroup
* @tc.desc : Cancel the taskGroup that have not been executed
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass060', 0, function (done) {
it('TaskPoolTestClass063', 0, async function (done) {
function addition(arg) {
"use concurrent"
let start = new Date().getTime();
while (new Date().getTime() - start < 2000) {
continue;
}
return arg + 1;
}
let i = 10;
let taskGroup1 = new taskpool.TaskGroup();
taskGroup1.addTask(addition, 10);
taskGroup1.addTask(addition, 20);
taskGroup1.addTask(addition, 30);
let taskGroup2 = new taskpool.TaskGroup();
let task1 = new taskpool.Task(addition, 100);
let task2 = new taskpool.Task(addition, 200);
let task3 = new taskpool.Task(addition, 300);
taskGroup2.addTask(task1);
taskGroup2.addTask(task2);
taskGroup2.addTask(task3);
taskpool.execute(taskGroup1);
taskpool.execute(taskGroup2).then(() => {
++i;
});
taskpool.cancel(taskGroup2);
expect(i).assertEqual(10)
done();
})
/**
* @tc.number : TaskPoolTestClass064
* @tc.name : Async Function Cancel taskGroup
* @tc.desc : Cancel the non-existent taskGroup
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass064', 0, async function (done) {
try {
var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300);
var task4 = new taskpool.Task(addition, 400);
var task5 = new taskpool.Task(addition, 500);
var task6 = new taskpool.Task(addition, 600);
var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6);
var start = new Date().getTime();
while (new Date().getTime() - start < 100) {
continue;
}
let taskGroup = new taskpool.TaskGroup();
taskpool.cancel(task6);
taskpool.cancel(task5);
taskpool.cancel(task4);
taskpool.cancel(task3);
taskpool.cancel(task2);
}
catch (e) {
taskpool.cancel(taskGroup);
} catch (e) {
expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
"BusinessError: The task group does not exist when it is canceled, taskpool:: can not find the taskGroup");
}
done();
})
/**
* @tc.number : TaskPoolTestClass061
* @tc.name : Sync Function Cancel task
* @tc.desc : Test Simultaneous use taskpool and worker
* @tc.number : TaskPoolTestClass065
* @tc.name : Async Function Cancel taskGroup
* @tc.desc : Cancel the executed taskGroup
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('TaskPoolTestClass061', 0, async function (done) {
function testTaskPool() {
function addition(arg) {
"use concurrent"
return arg + 1;
}
function additionDelay(arg) {
"use concurrent"
var start = new Date().getTime();
while (new Date().getTime() - start < 3000) {
continue;
}
return arg + 1;
}
it('TaskPoolTestClass065', 0, async function (done) {
function printArgs(args) {
"use concurrent"
return args;
}
try {
var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300);
let taskGroup1 = new taskpool.TaskGroup();
taskGroup1.addTask(printArgs, 10);
taskGroup1.addTask(printArgs, 20);
taskGroup1.addTask(printArgs, 30);
taskpool.execute(task1)
taskpool.execute(task2)
taskpool.execute(task3)
let taskGroup2 = new taskpool.TaskGroup();
let task1 = new taskpool.Task(printArgs, 100);
let task2 = new taskpool.Task(printArgs, 200);
let task3 = new taskpool.Task(printArgs, 300);
var start = new Date().getTime();
while (new Date().getTime() - start < 1000) {
continue;
}
for (let i = 1; i <= 10; i++) {
taskpool.cancel(task1);
}
}
catch (e) {
console.info("taskpoolXTS061 catch error: " + e);
}
}
function promiseCase() {
let p = new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(0)
}, 100)
}).then(undefined, (error) => {
})
return p
}
taskGroup2.addTask(task1);
taskGroup2.addTask(task2);
taskGroup2.addTask(task3);
let ss = new worker.ThreadWorker("entry/ets/workers/worker.js")
let res = 0
let flag = false
ss.onexit = function () {
flag = true
res++
}
testTaskPool();
for (let i = 0; i < 10; i++) {
ss.terminate();
}
while (!flag) {
await promiseCase()
}
expect(res).assertEqual(1)
taskpool.execute(taskGroup1);
taskpool.execute(taskGroup2);
setTimeout(()=>{
try {
taskpool.cancel(taskGroup1);
} catch (e) {
expect(e.toString()).assertEqual(
"BusinessError: The task group does not exist when it is canceled, taskpool:: can not find the taskGroup");
}
}, 3000);
done();
})
})
}
\ No newline at end of file
......@@ -2146,7 +2146,7 @@ describe('threadWorkerTest', function () {
let ss = new worker.ThreadWorker("entry/ets/workers/newworker_016.js");
let array = []
for (let i = 0; i < 10; i++) {
array[i] = CreateArray(i, 62);
array[i] = CreateArray(i, 65);
}
let res = 0;
......@@ -2172,7 +2172,7 @@ describe('threadWorkerTest', function () {
while (!isTerminate) {
await promiseCase();
}
expect(res).assertEqual(620)
expect(res).assertEqual(650)
done();
})
......
......@@ -1446,7 +1446,7 @@ describe('WorkerTest', function () {
let ss = new worker.Worker("entry/ets/workers/worker_016.js");
let array = []
for (let i = 0; i < 10; i++) {
array[i] = CreateArray(i, 62);
array[i] = CreateArray(i, 65);
}
let res = 0;
......@@ -1472,7 +1472,7 @@ describe('WorkerTest', function () {
while (!isTerminate) {
await promiseCase();
}
expect(res).assertEqual(620)
expect(res).assertEqual(650)
done();
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册