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

!7180 fix taskpool xts bugs

Merge pull request !7180 from cwx1148594/master
...@@ -16,9 +16,19 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -16,9 +16,19 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import taskpool from '@ohos.taskpool' import taskpool from '@ohos.taskpool'
import worker from "@ohos.worker" import worker from "@ohos.worker"
export default function TaskPoolTest() { export default function TaskPoolTest() {
describe('ActsAbilityTest', function (done) { describe('ActsAbilityTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
function promiseCase() {
let p = new Promise(function (resolve, reject) {
setTimeout(function () {
resolve()
}, 100)
}).then(undefined, (error) => {
})
return p
}
it('TaskPoolTestClass001', 0, async function (done) { it('TaskPoolTestClass001', 0, async function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
...@@ -311,10 +321,17 @@ describe('ActsAbilityTest', function (done) { ...@@ -311,10 +321,17 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result;
var isTerminate = false;
var task = new taskpool.Task(Sum, 10, 20) var task = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret).assertEqual(30); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual(30);
done(); done();
}) })
...@@ -326,9 +343,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -326,9 +343,16 @@ describe('ActsAbilityTest', function (done) {
return false; return false;
} }
var task = new taskpool.Task(Add, true, true) var task = new taskpool.Task(Add, true, true)
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret).assertEqual(true); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual(true);
done(); done();
}) })
...@@ -337,9 +361,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -337,9 +361,16 @@ describe('ActsAbilityTest', function (done) {
return value1 + value2; return value1 + value2;
} }
var task = new taskpool.Task(StrCat, "abc", "def") var task = new taskpool.Task(StrCat, "abc", "def")
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret).assertEqual("abcdef"); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual("abcdef");
done(); done();
}) })
...@@ -351,9 +382,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -351,9 +382,16 @@ describe('ActsAbilityTest', function (done) {
return value1+StrCat(value2,"hello"); return value1+StrCat(value2,"hello");
} }
var task = new taskpool.Task(Sum, "abc", "def"); var task = new taskpool.Task(Sum, "abc", "def");
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret).assertEqual("abcdefhello"); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual("abcdefhello");
done(); done();
}) })
...@@ -365,10 +403,17 @@ describe('ActsAbilityTest', function (done) { ...@@ -365,10 +403,17 @@ describe('ActsAbilityTest', function (done) {
return value; return value;
} }
var task = new taskpool.Task(Sum, [1,2], [3,4]); var task = new taskpool.Task(Sum, [1,2], [3,4]);
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret[0]).assertEqual(4); result = ret;
expect(ret[1]).assertEqual(6); isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result[0]).assertEqual(4);
expect(result[1]).assertEqual(6);
done(); done();
}) })
...@@ -380,9 +425,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -380,9 +425,16 @@ describe('ActsAbilityTest', function (done) {
return value; return value;
} }
var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}); var task = new taskpool.Task(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4});
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(JSON.stringify(ret)).assertEqual("{\"a\":4,\"b\":6}"); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}");
done(); done();
}) })
...@@ -391,9 +443,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -391,9 +443,16 @@ describe('ActsAbilityTest', function (done) {
return value1 + value2; return value1 + value2;
} }
var task = new taskpool.Task(Sum, 10); var task = new taskpool.Task(Sum, 10);
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret).assertEqual(NaN); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result.toString()).assertEqual("NaN");
done(); done();
}) })
...@@ -402,9 +461,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -402,9 +461,16 @@ describe('ActsAbilityTest', function (done) {
return value1 + value2; return value1 + value2;
} }
var task = new taskpool.Task(Sum, 10, 20, 30); var task = new taskpool.Task(Sum, 10, 20, 30);
var result;
var isTerminate = false;
taskpool.execute(task).then((ret) => { taskpool.execute(task).then((ret) => {
expect(ret).assertEqual(30); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual(30);
done(); done();
}) })
...@@ -412,15 +478,27 @@ describe('ActsAbilityTest', function (done) { ...@@ -412,15 +478,27 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
var task1 = new taskpool.Task(Sum, 10, 20); var task1 = new taskpool.Task(Sum, 10, 20);
taskpool.execute(task1).then((ret1) => { taskpool.execute(task1).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
var task2 = new taskpool.Task(Sum, 30, 40); var task2 = new taskpool.Task(Sum, 30, 40);
taskpool.execute(task2).then((ret2) => { taskpool.execute(task2).then((ret2) => {
expect(ret2).assertEqual(70); result2 = ret2;
isTerminate2 = true;
}) })
while (!isTerminate1 || !isTerminate2) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(70);
done(); done();
}) })
...@@ -428,15 +506,26 @@ describe('ActsAbilityTest', function (done) { ...@@ -428,15 +506,26 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
var task1 = new taskpool.Task(Sum, 10, 20) var task1 = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task1).then((ret1) => { taskpool.execute(task1).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
var task2 = new taskpool.Task(Sum, 10, 20) var task2 = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task2).then((ret2) => { taskpool.execute(task2).then((ret2) => {
expect(ret2).assertEqual(30); result2 = ret2;
isTerminate2 = true;
}) })
while (!isTerminate1 || !isTerminate2) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(30);
done(); done();
}) })
...@@ -444,13 +533,25 @@ describe('ActsAbilityTest', function (done) { ...@@ -444,13 +533,25 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
var task = new taskpool.Task(Sum, 10, 20) var task = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task).then((ret1) => { taskpool.execute(task).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
taskpool.execute(task).then((ret2) => { taskpool.execute(task).then((ret2) => {
expect(ret2).assertEqual(30); result2 = ret2;
isTerminate2 = true;
}) })
while (!isTerminate1 || !isTerminate2) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(30);
done(); done();
}) })
...@@ -462,22 +563,43 @@ describe('ActsAbilityTest', function (done) { ...@@ -462,22 +563,43 @@ describe('ActsAbilityTest', function (done) {
return value1 * value2; return value1 * value2;
} }
var result1;
var result2;
var result3;
var result4;
var isTerminate1 = false;
var isTerminate2 = false;
var isTerminate3 = false;
var isTerminate4 = false;
var task1 = new taskpool.Task(Sum, 10, 20) var task1 = new taskpool.Task(Sum, 10, 20)
taskpool.execute(task1).then((ret1) => { taskpool.execute(task1).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
var task2 = new taskpool.Task(Multi, 10, 20) var task2 = new taskpool.Task(Multi, 10, 20)
taskpool.execute(task2).then((ret2) => { taskpool.execute(task2).then((ret2) => {
expect(ret2).assertEqual(200); result2 = ret2;
isTerminate2 = true;
}) })
var task3 = new taskpool.Task(Sum, 10, 30) var task3 = new taskpool.Task(Sum, 10, 30)
taskpool.execute(task3).then((ret3) => { taskpool.execute(task3).then((ret3) => {
expect(ret3).assertEqual(40); result3 = ret3;
isTerminate3 = true;
}) })
var task4 = new taskpool.Task(Multi, 20, 20) var task4 = new taskpool.Task(Multi, 20, 20)
taskpool.execute(task4).then((ret4) => { taskpool.execute(task4).then((ret4) => {
expect(ret4).assertEqual(400); result4 = ret4;
isTerminate4 = true;
}) })
while (!isTerminate1 || !isTerminate2 || !isTerminate3 || !isTerminate4) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(200);
expect(result3).assertEqual(40);
expect(result4).assertEqual(400);
done(); done();
}) })
...@@ -485,9 +607,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -485,9 +607,16 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result;
var isTerminate = false;
taskpool.execute(Sum, 10, 20).then((ret) => { taskpool.execute(Sum, 10, 20).then((ret) => {
expect(ret).assertEqual(30); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual(30);
done(); done();
}) })
...@@ -498,9 +627,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -498,9 +627,16 @@ describe('ActsAbilityTest', function (done) {
else else
return false; return false;
} }
var result;
var isTerminate = false;
taskpool.execute(Add, true, false).then((ret) => { taskpool.execute(Add, true, false).then((ret) => {
expect(ret).assertEqual(false); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual(false);
done(); done();
}) })
...@@ -508,9 +644,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -508,9 +644,16 @@ describe('ActsAbilityTest', function (done) {
function StrCat(value1, value2) { function StrCat(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result;
var isTerminate = false;
taskpool.execute(StrCat, "abc", "def").then((ret) => { taskpool.execute(StrCat, "abc", "def").then((ret) => {
expect(ret).assertEqual("abcdef"); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual("abcdef");
done(); done();
}) })
...@@ -521,9 +664,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -521,9 +664,16 @@ describe('ActsAbilityTest', function (done) {
} }
return value1+StrCat(value2,"hello"); return value1+StrCat(value2,"hello");
} }
var result;
var isTerminate = false;
taskpool.execute(Sum, "abc", "def").then((ret) => { taskpool.execute(Sum, "abc", "def").then((ret) => {
expect(ret).assertEqual("abcdefhello"); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual("abcdefhello");
done(); done();
}) })
...@@ -534,10 +684,17 @@ describe('ActsAbilityTest', function (done) { ...@@ -534,10 +684,17 @@ describe('ActsAbilityTest', function (done) {
value[1] = arg1[1] + arg2[1]; value[1] = arg1[1] + arg2[1];
return value; return value;
} }
var result;
var isTerminate = false;
taskpool.execute(Sum, [1,2], [3,4]).then((ret) => { taskpool.execute(Sum, [1,2], [3,4]).then((ret) => {
expect(ret[0]).assertEqual(4); result = ret;
expect(ret[1]).assertEqual(6); isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result[0]).assertEqual(4);
expect(result[1]).assertEqual(6);
done(); done();
}) })
...@@ -548,9 +705,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -548,9 +705,16 @@ describe('ActsAbilityTest', function (done) {
value.b = arg1.b + arg2.b; value.b = arg1.b + arg2.b;
return value; return value;
} }
var result;
var isTerminate = false;
taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}).then((ret) => { taskpool.execute(Sum, {"a": 1, "b" : 2}, {"a": 3, "b" : 4}).then((ret) => {
expect(JSON.stringify(ret)).assertEqual("{\"a\":4,\"b\":6}"); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(JSON.stringify(result)).assertEqual("{\"a\":4,\"b\":6}");
done(); done();
}) })
...@@ -558,9 +722,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -558,9 +722,16 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result;
var isTerminate = false;
taskpool.execute(Sum, 10).then((ret) => { taskpool.execute(Sum, 10).then((ret) => {
expect(ret).assertEqual(NaN); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result.toString()).assertEqual("NaN");
done(); done();
}) })
...@@ -568,9 +739,16 @@ describe('ActsAbilityTest', function (done) { ...@@ -568,9 +739,16 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result;
var isTerminate = false;
taskpool.execute(Sum, 10, 20, 30).then((ret) => { taskpool.execute(Sum, 10, 20, 30).then((ret) => {
expect(ret).assertEqual(30); result = ret;
isTerminate = true;
}) })
while (!isTerminate) {
await promiseCase()
}
expect(result).assertEqual(30);
done(); done();
}) })
...@@ -578,12 +756,24 @@ describe('ActsAbilityTest', function (done) { ...@@ -578,12 +756,24 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
taskpool.execute(Sum, 10, 20).then((ret1) => { taskpool.execute(Sum, 10, 20).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
taskpool.execute(Sum, 30, 40).then((ret2) => { taskpool.execute(Sum, 30, 40).then((ret2) => {
expect(ret2).assertEqual(70); result2 = ret2;
isTerminate2 = true;
}) })
while (!isTerminate1 || !isTerminate2) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(70);
done(); done();
}) })
...@@ -591,12 +781,24 @@ describe('ActsAbilityTest', function (done) { ...@@ -591,12 +781,24 @@ describe('ActsAbilityTest', function (done) {
function Sum(value1, value2) { function Sum(value1, value2) {
return value1 + value2; return value1 + value2;
} }
var result1;
var result2;
var isTerminate1 = false;
var isTerminate2 = false;
taskpool.execute(Sum, 10, 20).then((ret1) => { taskpool.execute(Sum, 10, 20).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
taskpool.execute(Sum, 10, 20).then((ret2) => { taskpool.execute(Sum, 10, 20).then((ret2) => {
expect(ret2).assertEqual(30); result2 = ret2;
isTerminate2 = true;
}) })
while (!isTerminate1 || !isTerminate2) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(30);
done(); done();
}) })
...@@ -608,18 +810,38 @@ describe('ActsAbilityTest', function (done) { ...@@ -608,18 +810,38 @@ describe('ActsAbilityTest', function (done) {
return value1 * value2; return value1 * value2;
} }
var result1;
var result2;
var result3;
var result4;
var isTerminate1 = false;
var isTerminate2 = false;
var isTerminate3 = false;
var isTerminate4 = false;
taskpool.execute(Sum, 10, 20).then((ret1) => { taskpool.execute(Sum, 10, 20).then((ret1) => {
expect(ret1).assertEqual(30); result1 = ret1;
isTerminate1 = true;
}) })
taskpool.execute(Multi, 10, 20).then((ret2) => { taskpool.execute(Multi, 10, 20).then((ret2) => {
expect(ret2).assertEqual(200); result2 = ret2;
isTerminate2 = true;
}) })
taskpool.execute(Sum, 10, 30).then((ret3) => { taskpool.execute(Sum, 10, 30).then((ret3) => {
expect(ret3).assertEqual(40); result3 = ret3;
isTerminate3 = true;
}) })
taskpool.execute(Multi, 20, 20).then((ret4) => { taskpool.execute(Multi, 20, 20).then((ret4) => {
expect(ret4).assertEqual(400); result4 = ret4;
isTerminate4 = true;
}) })
while (!isTerminate1 || !isTerminate2 || !isTerminate3 || !isTerminate4) {
await promiseCase()
}
expect(result1).assertEqual(30);
expect(result2).assertEqual(200);
expect(result3).assertEqual(40);
expect(result4).assertEqual(400);
done(); done();
}) })
...@@ -643,7 +865,7 @@ describe('ActsAbilityTest', function (done) { ...@@ -643,7 +865,7 @@ describe('ActsAbilityTest', function (done) {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('TaskPoolTestClass049', 0, async function (done) { it('TaskPoolTestClass049', 0, async function (done) {
function addition(arg) { function addition(arg) {
return arg + 1; return arg + 1;
} }
...@@ -655,18 +877,18 @@ describe('ActsAbilityTest', function (done) { ...@@ -655,18 +877,18 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(additionDelay, 100); var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200); var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual(""); expect(e.toString()).assertEqual("");
} }
done(); done();
}) })
...@@ -691,18 +913,18 @@ describe('ActsAbilityTest', function (done) { ...@@ -691,18 +913,18 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(additionDelay, 100); var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200); var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual(""); expect(e.toString()).assertEqual("");
} }
done(); done();
}) })
...@@ -727,23 +949,24 @@ describe('ActsAbilityTest', function (done) { ...@@ -727,23 +949,24 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(additionDelay, 100); var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200); var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var start = new Date().getTime(); var start = new Date().getTime();
while (new Date().getTime() - start < 1000) { while (new Date().getTime() - start < 1000) {
continue; continue;
} }
taskpool.cancel(task1); taskpool.cancel(task1);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not cancel the running task"); expect(e.toString()).assertEqual(
"BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task");
} }
done(); done();
}) })
...@@ -768,23 +991,24 @@ describe('ActsAbilityTest', function (done) { ...@@ -768,23 +991,24 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(additionDelay, 100); var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200); var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var start = new Date().getTime(); var start = new Date().getTime();
while (new Date().getTime() - start < 1000) { while (new Date().getTime() - start < 1000) {
continue; continue;
} }
taskpool.cancel(task1); taskpool.cancel(task1);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not cancel the running task"); expect(e.toString()).assertEqual(
"BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task");
} }
done(); done();
}) })
...@@ -802,23 +1026,24 @@ describe('ActsAbilityTest', function (done) { ...@@ -802,23 +1026,24 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(addition, 100); var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200); var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var start = new Date().getTime(); var start = new Date().getTime();
while (new Date().getTime() - start < 1000) { while (new Date().getTime() - start < 1000) {
continue; continue;
} }
taskpool.cancel(task1); taskpool.cancel(task1);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -836,29 +1061,30 @@ describe('ActsAbilityTest', function (done) { ...@@ -836,29 +1061,30 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(addition, 100); var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200); var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var task4 = new taskpool.Task(addition, 400); var task4 = new taskpool.Task(addition, 400);
var task5 = new taskpool.Task(addition, 500); var task5 = new taskpool.Task(addition, 500);
var task6 = new taskpool.Task(addition, 600); var task6 = new taskpool.Task(addition, 600);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4); var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5); var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6); var result6 = taskpool.execute(task6);
var start = new Date().getTime(); var start = new Date().getTime();
while (new Date().getTime() - start < 1000) { while (new Date().getTime() - start < 1000) {
continue; continue;
} }
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -876,17 +1102,18 @@ describe('ActsAbilityTest', function (done) { ...@@ -876,17 +1102,18 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(addition, 100); var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200); var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -904,17 +1131,18 @@ describe('ActsAbilityTest', function (done) { ...@@ -904,17 +1131,18 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(addition, 100); var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200); var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -939,24 +1167,25 @@ describe('ActsAbilityTest', function (done) { ...@@ -939,24 +1167,25 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(additionDelay, 100); var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200); var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var start = new Date().getTime(); var start = new Date().getTime();
while (new Date().getTime() - start < 1000) { while (new Date().getTime() - start < 1000) {
continue; continue;
} }
taskpool.cancel(task3); taskpool.cancel(task3);
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -981,24 +1210,25 @@ describe('ActsAbilityTest', function (done) { ...@@ -981,24 +1210,25 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(additionDelay, 100); var task1 = new taskpool.Task(additionDelay, 100);
var task2 = new taskpool.Task(additionDelay, 200); var task2 = new taskpool.Task(additionDelay, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var start = new Date().getTime(); var start = new Date().getTime();
while (new Date().getTime() - start < 1000) { while (new Date().getTime() - start < 1000) {
continue; continue;
} }
taskpool.cancel(task3); taskpool.cancel(task3);
taskpool.cancel(task3); taskpool.cancel(task3);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -1016,28 +1246,34 @@ describe('ActsAbilityTest', function (done) { ...@@ -1016,28 +1246,34 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(addition, 100); var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200); var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var task4 = new taskpool.Task(addition, 400); var task4 = new taskpool.Task(addition, 400);
var task5 = new taskpool.Task(addition, 500); var task5 = new taskpool.Task(addition, 500);
var task6 = new taskpool.Task(addition, 600); var task6 = new taskpool.Task(addition, 600);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4); var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5); var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6); var result6 = taskpool.execute(task6);
taskpool.cancel(task6); var start = new Date().getTime();
taskpool.cancel(task5); while (new Date().getTime() - start < 100) {
taskpool.cancel(task4); continue;
taskpool.cancel(task3); }
taskpool.cancel(task2);
taskpool.cancel(task6);
taskpool.cancel(task5);
taskpool.cancel(task4);
taskpool.cancel(task3);
taskpool.cancel(task2);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
...@@ -1055,28 +1291,34 @@ describe('ActsAbilityTest', function (done) { ...@@ -1055,28 +1291,34 @@ describe('ActsAbilityTest', function (done) {
return arg + 1; return arg + 1;
} }
try { try {
var task1 = new taskpool.Task(addition, 100); var task1 = new taskpool.Task(addition, 100);
var task2 = new taskpool.Task(addition, 200); var task2 = new taskpool.Task(addition, 200);
var task3 = new taskpool.Task(addition, 300); var task3 = new taskpool.Task(addition, 300);
var task4 = new taskpool.Task(addition, 400); var task4 = new taskpool.Task(addition, 400);
var task5 = new taskpool.Task(addition, 500); var task5 = new taskpool.Task(addition, 500);
var task6 = new taskpool.Task(addition, 600); var task6 = new taskpool.Task(addition, 600);
var result1 = taskpool.execute(task1); var result1 = taskpool.execute(task1);
var result2 = taskpool.execute(task2); var result2 = taskpool.execute(task2);
var result3 = taskpool.execute(task3); var result3 = taskpool.execute(task3);
var result4 = taskpool.execute(task4); var result4 = taskpool.execute(task4);
var result5 = taskpool.execute(task5); var result5 = taskpool.execute(task5);
var result6 = taskpool.execute(task6); var result6 = taskpool.execute(task6);
taskpool.cancel(task6); var start = new Date().getTime();
taskpool.cancel(task5); while (new Date().getTime() - start < 100) {
taskpool.cancel(task4); continue;
taskpool.cancel(task3); }
taskpool.cancel(task2);
taskpool.cancel(task6);
taskpool.cancel(task5);
taskpool.cancel(task4);
taskpool.cancel(task3);
taskpool.cancel(task2);
} }
catch (e) { catch (e) {
expect(e.toString()).assertEqual("BusinessError: taskpool:: can not find the task"); expect(e.toString()).assertEqual(
"BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task");
} }
done(); done();
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册