Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
02f45609
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
02f45609
编写于
7月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!9043 modify and add taskpool xts
Merge pull request !9043 from buzhuyu/master
上级
8399b097
b84494b7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
525 addition
and
596 deletion
+525
-596
commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js
...ool_lib_standard/entry/src/main/ets/test/TaskPool.test.js
+521
-592
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
...lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
+2
-2
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
...r_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
+2
-2
未找到文件。
commonlibrary/ets_utils/taskpool_lib_standard/entry/src/main/ets/test/TaskPool.test.js
浏览文件 @
02f45609
...
@@ -29,17 +29,89 @@ describe('ActsAbilityTest', function () {
...
@@ -29,17 +29,89 @@ describe('ActsAbilityTest', function () {
return
p
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
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
let
result
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
expect
(
result
).
assertEqual
(
30
);
expect
(
result
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
2
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
3
'
,
0
,
async
function
(
done
)
{
function
Add
(
value1
,
value2
)
{
function
Add
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
if
(
value1
&
value2
)
if
(
value1
&
value2
)
...
@@ -47,33 +119,33 @@ describe('ActsAbilityTest', function () {
...
@@ -47,33 +119,33 @@ describe('ActsAbilityTest', function () {
else
else
return
false
;
return
false
;
}
}
var
result
=
await
taskpool
.
execute
(
Add
,
true
,
true
);
let
result
=
await
taskpool
.
execute
(
Add
,
true
,
true
);
expect
(
result
).
assertEqual
(
true
);
expect
(
result
).
assertEqual
(
true
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
3
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
4
'
,
0
,
async
function
(
done
)
{
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
=
await
taskpool
.
execute
(
StrCat
,
"
abc
"
,
"
def
"
);
let
result
=
await
taskpool
.
execute
(
StrCat
,
"
abc
"
,
"
def
"
);
expect
(
result
).
assertEqual
(
"
abcdef
"
);
expect
(
result
).
assertEqual
(
"
abcdef
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
4
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
5
'
,
0
,
async
function
(
done
)
{
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
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
"
);
result
=
await
taskpool
.
execute
(
StrCat
,
"
abc
"
,
"
def
"
);
expect
(
result
).
assertEqual
(
"
abcdef
"
);
expect
(
result
).
assertEqual
(
"
abcdef
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
5
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
6
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
...
@@ -81,12 +153,12 @@ describe('ActsAbilityTest', function () {
...
@@ -81,12 +153,12 @@ describe('ActsAbilityTest', function () {
}
}
return
value1
+
StrCat
(
value2
,
"
hello
"
);
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
"
);
expect
(
result
).
assertEqual
(
"
abcdefhello
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
6
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
7
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
[];
let
value
=
[];
...
@@ -94,13 +166,13 @@ describe('ActsAbilityTest', function () {
...
@@ -94,13 +166,13 @@ describe('ActsAbilityTest', function () {
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
return
value
;
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
[
0
]).
assertEqual
(
4
);
expect
(
result
[
1
]).
assertEqual
(
6
);
expect
(
result
[
1
]).
assertEqual
(
6
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
7
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
8
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
arg1
;
let
value
=
arg1
;
...
@@ -108,56 +180,56 @@ describe('ActsAbilityTest', function () {
...
@@ -108,56 +180,56 @@ describe('ActsAbilityTest', function () {
value
.
b
=
arg1
.
b
+
arg2
.
b
;
value
.
b
=
arg1
.
b
+
arg2
.
b
;
return
value
;
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}
"
);
expect
(
JSON
.
stringify
(
result
)).
assertEqual
(
"
{
\"
a
\"
:4,
\"
b
\"
:6}
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass00
8
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass00
9
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
=
await
taskpool
.
execute
(
Sum
,
10
);
let
result
=
await
taskpool
.
execute
(
Sum
,
10
);
expect
(
result
.
toString
()).
assertEqual
(
"
NaN
"
);
expect
(
result
.
toString
()).
assertEqual
(
"
NaN
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass0
09
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
10
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
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
);
expect
(
result
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
0
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
1
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
let
result1
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
var
result2
=
await
taskpool
.
execute
(
Sum
,
30
,
40
);
let
result2
=
await
taskpool
.
execute
(
Sum
,
30
,
40
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
70
);
expect
(
result2
).
assertEqual
(
70
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
1
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
2
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
let
result1
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
var
result2
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
let
result2
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
2
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
3
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
...
@@ -166,10 +238,10 @@ describe('ActsAbilityTest', function () {
...
@@ -166,10 +238,10 @@ describe('ActsAbilityTest', function () {
"
use concurrent
"
"
use concurrent
"
return
value1
*
value2
;
return
value1
*
value2
;
}
}
var
result1
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
let
result1
=
await
taskpool
.
execute
(
Sum
,
10
,
20
);
var
result2
=
await
taskpool
.
execute
(
Multi
,
10
,
20
);
let
result2
=
await
taskpool
.
execute
(
Multi
,
10
,
20
);
var
result3
=
await
taskpool
.
execute
(
Sum
,
10
,
30
);
let
result3
=
await
taskpool
.
execute
(
Sum
,
10
,
30
);
var
result4
=
await
taskpool
.
execute
(
Multi
,
20
,
20
);
let
result4
=
await
taskpool
.
execute
(
Multi
,
20
,
20
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
200
);
expect
(
result2
).
assertEqual
(
200
);
expect
(
result3
).
assertEqual
(
40
);
expect
(
result3
).
assertEqual
(
40
);
...
@@ -177,18 +249,18 @@ describe('ActsAbilityTest', function () {
...
@@ -177,18 +249,18 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
3
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
4
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
let
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
).
assertEqual
(
30
);
expect
(
result
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
4
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
5
'
,
0
,
async
function
(
done
)
{
function
Add
(
value1
,
value2
)
{
function
Add
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
if
(
value1
&
value2
)
if
(
value1
&
value2
)
...
@@ -196,24 +268,24 @@ describe('ActsAbilityTest', function () {
...
@@ -196,24 +268,24 @@ describe('ActsAbilityTest', function () {
else
else
return
false
;
return
false
;
}
}
var
task
=
new
taskpool
.
Task
(
Add
,
true
,
true
);
let
task
=
new
taskpool
.
Task
(
Add
,
true
,
true
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
).
assertEqual
(
true
);
expect
(
result
).
assertEqual
(
true
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
5
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
6
'
,
0
,
async
function
(
done
)
{
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
StrCat
,
"
abc
"
,
"
def
"
);
let
task
=
new
taskpool
.
Task
(
StrCat
,
"
abc
"
,
"
def
"
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
).
assertEqual
(
"
abcdef
"
);
expect
(
result
).
assertEqual
(
"
abcdef
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
6
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
7
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
...
@@ -221,13 +293,13 @@ describe('ActsAbilityTest', function () {
...
@@ -221,13 +293,13 @@ describe('ActsAbilityTest', function () {
}
}
return
value1
+
StrCat
(
value2
,
"
hello
"
);
return
value1
+
StrCat
(
value2
,
"
hello
"
);
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
"
abc
"
,
"
def
"
);
let
task
=
new
taskpool
.
Task
(
Sum
,
"
abc
"
,
"
def
"
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
).
assertEqual
(
"
abcdefhello
"
);
expect
(
result
).
assertEqual
(
"
abcdefhello
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
7
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
8
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
[];
let
value
=
[];
...
@@ -235,14 +307,14 @@ describe('ActsAbilityTest', function () {
...
@@ -235,14 +307,14 @@ describe('ActsAbilityTest', function () {
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
return
value
;
return
value
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
[
1
,
2
],
[
3
,
4
]);
let
task
=
new
taskpool
.
Task
(
Sum
,
[
1
,
2
],
[
3
,
4
]);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
[
0
]).
assertEqual
(
4
);
expect
(
result
[
0
]).
assertEqual
(
4
);
expect
(
result
[
1
]).
assertEqual
(
6
);
expect
(
result
[
1
]).
assertEqual
(
6
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass01
8
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass01
9
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
arg1
;
let
value
=
arg1
;
...
@@ -250,76 +322,76 @@ describe('ActsAbilityTest', function () {
...
@@ -250,76 +322,76 @@ describe('ActsAbilityTest', function () {
value
.
b
=
arg1
.
b
+
arg2
.
b
;
value
.
b
=
arg1
.
b
+
arg2
.
b
;
return
value
;
return
value
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
{
"
a
"
:
1
,
"
b
"
:
2
},
{
"
a
"
:
3
,
"
b
"
:
4
});
let
task
=
new
taskpool
.
Task
(
Sum
,
{
"
a
"
:
1
,
"
b
"
:
2
},
{
"
a
"
:
3
,
"
b
"
:
4
});
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
JSON
.
stringify
(
result
)).
assertEqual
(
"
{
\"
a
\"
:4,
\"
b
\"
:6}
"
);
expect
(
JSON
.
stringify
(
result
)).
assertEqual
(
"
{
\"
a
\"
:4,
\"
b
\"
:6}
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass0
19
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
20
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
10
);
let
task
=
new
taskpool
.
Task
(
Sum
,
10
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
.
toString
()).
assertEqual
(
"
NaN
"
);
expect
(
result
.
toString
()).
assertEqual
(
"
NaN
"
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
0
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
1
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
,
30
);
let
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
,
30
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
).
assertEqual
(
30
);
expect
(
result
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
1
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
2
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
let
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
var
result1
=
await
taskpool
.
execute
(
task
);
let
result1
=
await
taskpool
.
execute
(
task
);
var
result2
=
await
taskpool
.
execute
(
task
);
let
result2
=
await
taskpool
.
execute
(
task
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
2
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
3
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task1
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
let
task1
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
var
task2
=
new
taskpool
.
Task
(
Sum
,
30
,
40
);
let
task2
=
new
taskpool
.
Task
(
Sum
,
30
,
40
);
var
result1
=
await
taskpool
.
execute
(
task1
);
let
result1
=
await
taskpool
.
execute
(
task1
);
var
result2
=
await
taskpool
.
execute
(
task2
);
let
result2
=
await
taskpool
.
execute
(
task2
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
70
);
expect
(
result2
).
assertEqual
(
70
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
3
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
4
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task1
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
let
task1
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
var
task2
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
let
task2
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
var
result1
=
await
taskpool
.
execute
(
task1
);
let
result1
=
await
taskpool
.
execute
(
task1
);
var
result2
=
await
taskpool
.
execute
(
task2
);
let
result2
=
await
taskpool
.
execute
(
task2
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
30
);
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
4
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
5
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
...
@@ -328,14 +400,14 @@ describe('ActsAbilityTest', function () {
...
@@ -328,14 +400,14 @@ describe('ActsAbilityTest', function () {
"
use concurrent
"
"
use concurrent
"
return
value1
*
value2
;
return
value1
*
value2
;
}
}
var
task1
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
let
task1
=
new
taskpool
.
Task
(
Sum
,
10
,
20
);
var
result1
=
await
taskpool
.
execute
(
task1
);
let
result1
=
await
taskpool
.
execute
(
task1
);
var
task2
=
new
taskpool
.
Task
(
Multi
,
10
,
20
);
let
task2
=
new
taskpool
.
Task
(
Multi
,
10
,
20
);
var
result2
=
await
taskpool
.
execute
(
task2
);
let
result2
=
await
taskpool
.
execute
(
task2
);
var
task3
=
new
taskpool
.
Task
(
Sum
,
10
,
30
);
let
task3
=
new
taskpool
.
Task
(
Sum
,
10
,
30
);
var
result3
=
await
taskpool
.
execute
(
task3
);
let
result3
=
await
taskpool
.
execute
(
task3
);
var
task4
=
new
taskpool
.
Task
(
Multi
,
20
,
20
);
let
task4
=
new
taskpool
.
Task
(
Multi
,
20
,
20
);
var
result4
=
await
taskpool
.
execute
(
task4
);
let
result4
=
await
taskpool
.
execute
(
task4
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result1
).
assertEqual
(
30
);
expect
(
result2
).
assertEqual
(
200
);
expect
(
result2
).
assertEqual
(
200
);
expect
(
result3
).
assertEqual
(
40
);
expect
(
result3
).
assertEqual
(
40
);
...
@@ -343,14 +415,14 @@ describe('ActsAbilityTest', function () {
...
@@ -343,14 +415,14 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
5
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
6
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
var
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
)
let
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
)
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -362,7 +434,7 @@ describe('ActsAbilityTest', function () {
...
@@ -362,7 +434,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
6
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
7
'
,
0
,
async
function
(
done
)
{
function
Add
(
value1
,
value2
)
{
function
Add
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
if
(
value1
&
value2
)
if
(
value1
&
value2
)
...
@@ -370,9 +442,9 @@ describe('ActsAbilityTest', function () {
...
@@ -370,9 +442,9 @@ describe('ActsAbilityTest', function () {
else
else
return
false
;
return
false
;
}
}
var
task
=
new
taskpool
.
Task
(
Add
,
true
,
true
)
let
task
=
new
taskpool
.
Task
(
Add
,
true
,
true
)
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -384,14 +456,14 @@ describe('ActsAbilityTest', function () {
...
@@ -384,14 +456,14 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
7
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
8
'
,
0
,
async
function
(
done
)
{
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
StrCat
,
"
abc
"
,
"
def
"
)
let
task
=
new
taskpool
.
Task
(
StrCat
,
"
abc
"
,
"
def
"
)
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -403,7 +475,7 @@ describe('ActsAbilityTest', function () {
...
@@ -403,7 +475,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass02
8
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass02
9
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
...
@@ -411,9 +483,9 @@ describe('ActsAbilityTest', function () {
...
@@ -411,9 +483,9 @@ describe('ActsAbilityTest', function () {
}
}
return
value1
+
StrCat
(
value2
,
"
hello
"
);
return
value1
+
StrCat
(
value2
,
"
hello
"
);
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
"
abc
"
,
"
def
"
);
let
task
=
new
taskpool
.
Task
(
Sum
,
"
abc
"
,
"
def
"
);
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -425,7 +497,7 @@ describe('ActsAbilityTest', function () {
...
@@ -425,7 +497,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass0
29
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
30
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
[];
let
value
=
[];
...
@@ -433,9 +505,9 @@ describe('ActsAbilityTest', function () {
...
@@ -433,9 +505,9 @@ describe('ActsAbilityTest', function () {
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
return
value
;
return
value
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
[
1
,
2
],
[
3
,
4
]);
let
task
=
new
taskpool
.
Task
(
Sum
,
[
1
,
2
],
[
3
,
4
]);
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -448,7 +520,7 @@ describe('ActsAbilityTest', function () {
...
@@ -448,7 +520,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
0
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
1
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
arg1
;
let
value
=
arg1
;
...
@@ -456,9 +528,9 @@ describe('ActsAbilityTest', function () {
...
@@ -456,9 +528,9 @@ describe('ActsAbilityTest', function () {
value
.
b
=
arg1
.
b
+
arg2
.
b
;
value
.
b
=
arg1
.
b
+
arg2
.
b
;
return
value
;
return
value
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
{
"
a
"
:
1
,
"
b
"
:
2
},
{
"
a
"
:
3
,
"
b
"
:
4
});
let
task
=
new
taskpool
.
Task
(
Sum
,
{
"
a
"
:
1
,
"
b
"
:
2
},
{
"
a
"
:
3
,
"
b
"
:
4
});
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -470,14 +542,14 @@ describe('ActsAbilityTest', function () {
...
@@ -470,14 +542,14 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
1
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
2
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
10
);
let
task
=
new
taskpool
.
Task
(
Sum
,
10
);
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -489,14 +561,14 @@ describe('ActsAbilityTest', function () {
...
@@ -489,14 +561,14 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
2
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
3
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
,
30
);
let
task
=
new
taskpool
.
Task
(
Sum
,
10
,
20
,
30
);
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -508,23 +580,23 @@ describe('ActsAbilityTest', function () {
...
@@ -508,23 +580,23 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
3
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
4
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
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
)
=>
{
taskpool
.
execute
(
task1
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
isTerminate1
=
true
;
isTerminate1
=
true
;
})
})
var
task2
=
new
taskpool
.
Task
(
Sum
,
30
,
40
);
let
task2
=
new
taskpool
.
Task
(
Sum
,
30
,
40
);
taskpool
.
execute
(
task2
).
then
((
ret2
)
=>
{
taskpool
.
execute
(
task2
).
then
((
ret2
)
=>
{
result2
=
ret2
;
result2
=
ret2
;
isTerminate2
=
true
;
isTerminate2
=
true
;
...
@@ -537,22 +609,22 @@ describe('ActsAbilityTest', function () {
...
@@ -537,22 +609,22 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
4
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
5
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
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
)
=>
{
taskpool
.
execute
(
task1
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
isTerminate1
=
true
;
isTerminate1
=
true
;
})
})
var
task2
=
new
taskpool
.
Task
(
Sum
,
10
,
20
)
let
task2
=
new
taskpool
.
Task
(
Sum
,
10
,
20
)
taskpool
.
execute
(
task2
).
then
((
ret2
)
=>
{
taskpool
.
execute
(
task2
).
then
((
ret2
)
=>
{
result2
=
ret2
;
result2
=
ret2
;
isTerminate2
=
true
;
isTerminate2
=
true
;
...
@@ -565,17 +637,17 @@ describe('ActsAbilityTest', function () {
...
@@ -565,17 +637,17 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
5
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
6
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
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
)
=>
{
taskpool
.
execute
(
task
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
isTerminate1
=
true
;
isTerminate1
=
true
;
...
@@ -592,7 +664,7 @@ describe('ActsAbilityTest', function () {
...
@@ -592,7 +664,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
6
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
7
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
...
@@ -602,31 +674,31 @@ describe('ActsAbilityTest', function () {
...
@@ -602,31 +674,31 @@ describe('ActsAbilityTest', function () {
return
value1
*
value2
;
return
value1
*
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
result3
;
let
result3
;
var
result4
;
let
result4
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
false
;
let
isTerminate2
=
false
;
var
isTerminate3
=
false
;
let
isTerminate3
=
false
;
var
isTerminate4
=
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
)
=>
{
taskpool
.
execute
(
task1
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
isTerminate1
=
true
;
isTerminate1
=
true
;
})
})
var
task2
=
new
taskpool
.
Task
(
Multi
,
10
,
20
)
let
task2
=
new
taskpool
.
Task
(
Multi
,
10
,
20
)
taskpool
.
execute
(
task2
).
then
((
ret2
)
=>
{
taskpool
.
execute
(
task2
).
then
((
ret2
)
=>
{
result2
=
ret2
;
result2
=
ret2
;
isTerminate2
=
true
;
isTerminate2
=
true
;
})
})
var
task3
=
new
taskpool
.
Task
(
Sum
,
10
,
30
)
let
task3
=
new
taskpool
.
Task
(
Sum
,
10
,
30
)
taskpool
.
execute
(
task3
).
then
((
ret3
)
=>
{
taskpool
.
execute
(
task3
).
then
((
ret3
)
=>
{
result3
=
ret3
;
result3
=
ret3
;
isTerminate3
=
true
;
isTerminate3
=
true
;
})
})
var
task4
=
new
taskpool
.
Task
(
Multi
,
20
,
20
)
let
task4
=
new
taskpool
.
Task
(
Multi
,
20
,
20
)
taskpool
.
execute
(
task4
).
then
((
ret4
)
=>
{
taskpool
.
execute
(
task4
).
then
((
ret4
)
=>
{
result4
=
ret4
;
result4
=
ret4
;
isTerminate4
=
true
;
isTerminate4
=
true
;
...
@@ -642,13 +714,13 @@ describe('ActsAbilityTest', function () {
...
@@ -642,13 +714,13 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
7
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
8
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret
)
=>
{
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -660,7 +732,7 @@ describe('ActsAbilityTest', function () {
...
@@ -660,7 +732,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass03
8
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass03
9
'
,
0
,
async
function
(
done
)
{
function
Add
(
value1
,
value2
)
{
function
Add
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
if
(
value1
&
value2
)
if
(
value1
&
value2
)
...
@@ -668,8 +740,8 @@ describe('ActsAbilityTest', function () {
...
@@ -668,8 +740,8 @@ describe('ActsAbilityTest', function () {
else
else
return
false
;
return
false
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
Add
,
true
,
false
).
then
((
ret
)
=>
{
taskpool
.
execute
(
Add
,
true
,
false
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -681,13 +753,13 @@ describe('ActsAbilityTest', function () {
...
@@ -681,13 +753,13 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass0
39
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
40
'
,
0
,
async
function
(
done
)
{
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
StrCat
,
"
abc
"
,
"
def
"
).
then
((
ret
)
=>
{
taskpool
.
execute
(
StrCat
,
"
abc
"
,
"
def
"
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -699,7 +771,7 @@ describe('ActsAbilityTest', function () {
...
@@ -699,7 +771,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
0
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
1
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
function
StrCat
(
value1
,
value2
)
{
function
StrCat
(
value1
,
value2
)
{
...
@@ -707,8 +779,8 @@ describe('ActsAbilityTest', function () {
...
@@ -707,8 +779,8 @@ describe('ActsAbilityTest', function () {
}
}
return
value1
+
StrCat
(
value2
,
"
hello
"
);
return
value1
+
StrCat
(
value2
,
"
hello
"
);
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
Sum
,
"
abc
"
,
"
def
"
).
then
((
ret
)
=>
{
taskpool
.
execute
(
Sum
,
"
abc
"
,
"
def
"
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -720,7 +792,7 @@ describe('ActsAbilityTest', function () {
...
@@ -720,7 +792,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
1
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
2
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
[];
let
value
=
[];
...
@@ -728,8 +800,8 @@ describe('ActsAbilityTest', function () {
...
@@ -728,8 +800,8 @@ describe('ActsAbilityTest', function () {
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
value
[
1
]
=
arg1
[
1
]
+
arg2
[
1
];
return
value
;
return
value
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
Sum
,
[
1
,
2
],
[
3
,
4
]).
then
((
ret
)
=>
{
taskpool
.
execute
(
Sum
,
[
1
,
2
],
[
3
,
4
]).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -742,7 +814,7 @@ describe('ActsAbilityTest', function () {
...
@@ -742,7 +814,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
2
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
3
'
,
0
,
async
function
(
done
)
{
function
Sum
(
arg1
,
arg2
)
{
function
Sum
(
arg1
,
arg2
)
{
"
use concurrent
"
"
use concurrent
"
let
value
=
arg1
;
let
value
=
arg1
;
...
@@ -750,8 +822,8 @@ describe('ActsAbilityTest', function () {
...
@@ -750,8 +822,8 @@ describe('ActsAbilityTest', function () {
value
.
b
=
arg1
.
b
+
arg2
.
b
;
value
.
b
=
arg1
.
b
+
arg2
.
b
;
return
value
;
return
value
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
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
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -763,13 +835,13 @@ describe('ActsAbilityTest', function () {
...
@@ -763,13 +835,13 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
3
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
4
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
Sum
,
10
).
then
((
ret
)
=>
{
taskpool
.
execute
(
Sum
,
10
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -781,13 +853,13 @@ describe('ActsAbilityTest', function () {
...
@@ -781,13 +853,13 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
4
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
5
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result
;
let
result
;
var
isTerminate
=
false
;
let
isTerminate
=
false
;
taskpool
.
execute
(
Sum
,
10
,
20
,
30
).
then
((
ret
)
=>
{
taskpool
.
execute
(
Sum
,
10
,
20
,
30
).
then
((
ret
)
=>
{
result
=
ret
;
result
=
ret
;
isTerminate
=
true
;
isTerminate
=
true
;
...
@@ -799,15 +871,15 @@ describe('ActsAbilityTest', function () {
...
@@ -799,15 +871,15 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
5
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
6
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
false
;
let
isTerminate2
=
false
;
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret1
)
=>
{
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
...
@@ -825,15 +897,15 @@ describe('ActsAbilityTest', function () {
...
@@ -825,15 +897,15 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
6
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
7
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
false
;
let
isTerminate2
=
false
;
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret1
)
=>
{
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
...
@@ -851,7 +923,7 @@ describe('ActsAbilityTest', function () {
...
@@ -851,7 +923,7 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
7
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
8
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
...
@@ -861,14 +933,14 @@ describe('ActsAbilityTest', function () {
...
@@ -861,14 +933,14 @@ describe('ActsAbilityTest', function () {
return
value1
*
value2
;
return
value1
*
value2
;
}
}
var
result1
;
let
result1
;
var
result2
;
let
result2
;
var
result3
;
let
result3
;
var
result4
;
let
result4
;
var
isTerminate1
=
false
;
let
isTerminate1
=
false
;
var
isTerminate2
=
false
;
let
isTerminate2
=
false
;
var
isTerminate3
=
false
;
let
isTerminate3
=
false
;
var
isTerminate4
=
false
;
let
isTerminate4
=
false
;
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret1
)
=>
{
taskpool
.
execute
(
Sum
,
10
,
20
).
then
((
ret1
)
=>
{
result1
=
ret1
;
result1
=
ret1
;
...
@@ -896,13 +968,13 @@ describe('ActsAbilityTest', function () {
...
@@ -896,13 +968,13 @@ describe('ActsAbilityTest', function () {
done
();
done
();
})
})
it
(
'
TaskPoolTestClass04
8
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass04
9
'
,
0
,
async
function
(
done
)
{
function
Sum
(
value1
,
value2
)
{
function
Sum
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
return
value1
+
value2
;
return
value1
+
value2
;
}
}
try
{
try
{
var
result
=
await
taskpool
.
execute
(
Sum
);
let
result
=
await
taskpool
.
execute
(
Sum
);
}
catch
(
e
)
{
}
catch
(
e
)
{
expect
(
e
.
toString
()).
assertEqual
(
"
BusinessError: taskpool:: first param must be object when argc is one
"
);
expect
(
e
.
toString
()).
assertEqual
(
"
BusinessError: taskpool:: first param must be object when argc is one
"
);
}
}
...
@@ -910,14 +982,14 @@ describe('ActsAbilityTest', function () {
...
@@ -910,14 +982,14 @@ describe('ActsAbilityTest', function () {
})
})
/**
/**
* @tc.number : TaskPoolTestClass0
61
* @tc.number : TaskPoolTestClass0
49
* @tc.name : Async Function about priority task
* @tc.name : Async Function about priority task
* @tc.desc : Execute priority tasks
* @tc.desc : Execute priority tasks
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass0
61
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
50
'
,
0
,
async
function
(
done
)
{
function
testTime
()
{
function
testTime
()
{
"
use concurrent
"
;
"
use concurrent
"
;
return
Date
.
now
();
return
Date
.
now
();
...
@@ -963,7 +1035,15 @@ describe('ActsAbilityTest', function () {
...
@@ -963,7 +1035,15 @@ describe('ActsAbilityTest', function () {
done
();
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
)
{
async
function
func
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
let
result
=
await
new
Promise
((
resolve
,
reject
)
=>
{
let
result
=
await
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -972,12 +1052,20 @@ describe('ActsAbilityTest', function () {
...
@@ -972,12 +1052,20 @@ describe('ActsAbilityTest', function () {
})
})
return
result
;
return
result
;
}
}
var
result
=
await
taskpool
.
execute
(
func
,
10
,
20
);
let
result
=
await
taskpool
.
execute
(
func
,
10
,
20
);
expect
(
result
).
assertEqual
(
30
);
expect
(
result
).
assertEqual
(
30
);
done
();
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
)
{
async
function
func
(
value1
,
value2
)
{
"
use concurrent
"
"
use concurrent
"
let
result
=
await
new
Promise
((
resolve
,
reject
)
=>
{
let
result
=
await
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -986,318 +1074,181 @@ describe('ActsAbilityTest', function () {
...
@@ -986,318 +1074,181 @@ describe('ActsAbilityTest', function () {
})
})
return
result
;
return
result
;
}
}
var
task
=
new
taskpool
.
Task
(
func
,
10
,
20
);
let
task
=
new
taskpool
.
Task
(
func
,
10
,
20
);
var
result
=
await
taskpool
.
execute
(
task
);
let
result
=
await
taskpool
.
execute
(
task
);
expect
(
result
).
assertEqual
(
30
);
expect
(
result
).
assertEqual
(
30
);
done
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass0
49
* @tc.number : TaskPoolTestClass0
53
* @tc.name : Async
Function Cancel task
* @tc.name : Async
function execute taskGroup
* @tc.desc :
Cancel tasks that have not been executed
* @tc.desc :
Execute async function
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass049
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass053
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
printArgs
(
args
)
{
"
use concurrent
"
"
use concurrent
"
return
arg
+
1
;
return
args
;
}
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
);
}
}
catch
(
e
)
{
expect
(
e
.
toString
()).
assertEqual
(
""
);
}
done
();
})
/**
let
taskGroup
=
new
taskpool
.
TaskGroup
();
* @tc.number : TaskPoolTestClass050
taskGroup
.
addTask
(
printArgs
,
10
);
* @tc.name : Sync Function Cancel task
taskGroup
.
addTask
(
printArgs
,
20
);
* @tc.desc : Cancel tasks that have not been executed
taskGroup
.
addTask
(
printArgs
,
30
);
* @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
;
}
taskpool
.
cancel
(
task11
);
taskpool
.
execute
(
taskGroup
).
then
((
res
)
=>
{
}
expect
(
res
[
0
]).
assertEqual
(
10
);
catch
(
e
)
{
expect
(
res
[
1
]).
assertEqual
(
20
);
expect
(
e
.
toString
()).
assertEqual
(
""
);
expect
(
res
[
2
]).
assertEqual
(
30
);
}
}
);
done
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass05
1
* @tc.number : TaskPoolTestClass05
4
* @tc.name : Async
Function Cancel task
* @tc.name : Async
function execute taskGroup
* @tc.desc :
Cancel the task in progress
* @tc.desc :
Execute async function
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass051
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass054
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
printArgs
(
args
)
{
"
use concurrent
"
return
arg
+
1
;
}
function
additionDelay
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
var
start
=
new
Date
().
getTime
();
return
args
;
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
)
{
continue
;
}
taskpool
.
cancel
(
task1
);
let
taskGroup
=
new
taskpool
.
TaskGroup
();
}
let
task1
=
new
taskpool
.
Task
(
printArgs
,
100
);
catch
(
e
)
{
let
task2
=
new
taskpool
.
Task
(
printArgs
,
200
);
expect
(
e
.
toString
()).
assertEqual
(
let
task3
=
new
taskpool
.
Task
(
printArgs
,
300
);
"
BusinessError: The task is executing when it is canceled, taskpool:: can not cancel the running task
"
);
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
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass05
2
* @tc.number : TaskPoolTestClass05
5
* @tc.name : S
ync Function Cancel
task
* @tc.name : S
etTransferList for
task
* @tc.desc :
Cancel the task in progress
* @tc.desc :
Set transfer list for the task
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass052
'
,
0
,
function
(
done
)
{
it
(
'
TaskPoolTestClass055
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
let
buffer
=
new
ArrayBuffer
(
8
);
"
use concurrent
"
let
view
=
new
Uint8Array
(
buffer
);
return
arg
+
1
;
let
buffer1
=
new
ArrayBuffer
(
16
);
}
let
view1
=
new
Uint8Array
(
buffer1
);
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
();
function
testTransfer
(
arg1
,
arg2
)
{
while
(
new
Date
().
getTime
()
-
start
<
1000
)
{
"
use concurrent
"
continue
;
return
arg1
.
byteLength
+
arg2
.
byteLength
;
}
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
task
=
new
taskpool
.
Task
(
testTransfer
,
view
,
view1
);
task
.
setTransferList
([
view
.
buffer
,
view1
.
buffer
]);
taskpool
.
execute
(
task
).
then
((
res
)
=>
{
expect
(
res
).
assertEqual
(
24
);
});
done
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass05
3
* @tc.number : TaskPoolTestClass05
6
* @tc.name : Async Function Cancel task
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel t
he executed task
* @tc.desc : Cancel t
asks that have not been executed
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass05
3
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass05
6
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
inspectStatus
(
arg
)
{
"
use concurrent
"
"
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
);
let
task
=
new
taskpool
.
Task
(
inspectStatus
,
100
);
}
taskpool
.
execute
(
task
);
catch
(
e
)
{
taskpool
.
cancel
(
task
);
expect
(
e
.
toString
()).
assertEqual
(
expect
(
taskpool
.
Task
.
isCanceled
()
==
false
);
"
BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task
"
);
}
done
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass05
4
* @tc.number : TaskPoolTestClass05
7
* @tc.name :
S
ync Function Cancel task
* @tc.name :
As
ync Function Cancel task
* @tc.desc : Cancel the
executed task
* @tc.desc : Cancel the
task in progress
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass05
4
'
,
0
,
function
(
done
)
{
it
(
'
TaskPoolTestClass05
7
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
inspectStatus
(
arg
)
{
"
use concurrent
"
"
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
);
try
{
}
let
task1
=
new
taskpool
.
Task
(
inspectStatus
,
100
);
catch
(
e
)
{
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
(
expect
(
e
.
toString
()).
assertEqual
(
"
BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task
"
);
"
BusinessError: The task does not exist when it is canceled, taskpool:: can not find the task
"
);
}
}
expect
(
taskpool
.
Task
.
isCanceled
()
==
false
);
done
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass05
5
* @tc.number : TaskPoolTestClass05
8
* @tc.name : Async Function Cancel task
* @tc.name : Async Function Cancel task
* @tc.desc : Cancel
nonexistent
task
* @tc.desc : Cancel
the executed
task
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass05
5
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass05
8
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
return
arg
+
1
;
return
arg
+
1
;
}
}
try
{
try
{
var
task1
=
new
taskpool
.
Task
(
addition
,
100
);
let
task1
=
new
taskpool
.
Task
(
addition
,
100
);
var
task2
=
new
taskpool
.
Task
(
addition
,
200
);
let
task2
=
new
taskpool
.
Task
(
addition
,
200
);
var
task3
=
new
taskpool
.
Task
(
addition
,
300
);
let
task3
=
new
taskpool
.
Task
(
addition
,
300
);
var
result1
=
taskpool
.
execute
(
task1
);
let
result1
=
taskpool
.
execute
(
task1
);
var
result2
=
taskpool
.
execute
(
task2
);
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
)
{
catch
(
e
)
{
expect
(
e
.
toString
()).
assertEqual
(
expect
(
e
.
toString
()).
assertEqual
(
...
@@ -1307,25 +1258,25 @@ describe('ActsAbilityTest', function () {
...
@@ -1307,25 +1258,25 @@ describe('ActsAbilityTest', function () {
})
})
/**
/**
* @tc.number : TaskPoolTestClass05
6
* @tc.number : TaskPoolTestClass05
9
* @tc.name :
S
ync Function Cancel task
* @tc.name :
As
ync Function Cancel task
* @tc.desc : Cancel nonexistent task
* @tc.desc : Cancel nonexistent task
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass05
6
'
,
0
,
function
(
done
)
{
it
(
'
TaskPoolTestClass05
9
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
return
arg
+
1
;
return
arg
+
1
;
}
}
try
{
try
{
var
task1
=
new
taskpool
.
Task
(
addition
,
100
);
let
task1
=
new
taskpool
.
Task
(
addition
,
100
);
var
task2
=
new
taskpool
.
Task
(
addition
,
200
);
let
task2
=
new
taskpool
.
Task
(
addition
,
200
);
var
task3
=
new
taskpool
.
Task
(
addition
,
300
);
let
task3
=
new
taskpool
.
Task
(
addition
,
300
);
var
result1
=
taskpool
.
execute
(
task1
);
let
result1
=
taskpool
.
execute
(
task1
);
var
result2
=
taskpool
.
execute
(
task2
);
let
result2
=
taskpool
.
execute
(
task2
);
taskpool
.
cancel
(
task3
);
taskpool
.
cancel
(
task3
);
}
}
...
@@ -1337,36 +1288,36 @@ describe('ActsAbilityTest', function () {
...
@@ -1337,36 +1288,36 @@ describe('ActsAbilityTest', function () {
})
})
/**
/**
* @tc.number : TaskPoolTestClass0
57
* @tc.number : TaskPoolTestClass0
60
* @tc.name : Async Function Cancel task
* @tc.name : Async Function Cancel task
* @tc.desc : Canceling unexecuted tasks multiple times
* @tc.desc : Canceling unexecuted tasks multiple times
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass0
57
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
60
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
return
arg
+
1
;
return
arg
+
1
;
}
}
function
additionDelay
(
arg
)
{
function
additionDelay
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
var
start
=
new
Date
().
getTime
();
let
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
3000
)
{
while
(
new
Date
().
getTime
()
-
start
<
3000
)
{
continue
;
continue
;
}
}
return
arg
+
1
;
return
arg
+
1
;
}
}
try
{
try
{
var
task1
=
new
taskpool
.
Task
(
additionDelay
,
100
);
let
task1
=
new
taskpool
.
Task
(
additionDelay
,
100
);
var
task2
=
new
taskpool
.
Task
(
additionDelay
,
200
);
let
task2
=
new
taskpool
.
Task
(
additionDelay
,
200
);
var
task3
=
new
taskpool
.
Task
(
addition
,
300
);
let
task3
=
new
taskpool
.
Task
(
addition
,
300
);
var
result1
=
taskpool
.
execute
(
task1
);
let
result1
=
taskpool
.
execute
(
task1
);
var
result2
=
taskpool
.
execute
(
task2
);
let
result2
=
taskpool
.
execute
(
task2
);
var
result3
=
taskpool
.
execute
(
task3
);
let
result3
=
taskpool
.
execute
(
task3
);
var
start
=
new
Date
().
getTime
();
let
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
1000
)
{
while
(
new
Date
().
getTime
()
-
start
<
1000
)
{
continue
;
continue
;
}
}
...
@@ -1382,42 +1333,43 @@ describe('ActsAbilityTest', function () {
...
@@ -1382,42 +1333,43 @@ describe('ActsAbilityTest', function () {
})
})
/**
/**
* @tc.number : TaskPoolTestClass0
58
* @tc.number : TaskPoolTestClass0
61
* @tc.name :
S
ync Function Cancel task
* @tc.name :
As
ync Function Cancel task
* @tc.desc : Cancel
ing unexecuted tasks multiple times
* @tc.desc : Cancel
all tasks in sequence
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass0
58
'
,
0
,
function
(
done
)
{
it
(
'
TaskPoolTestClass0
61
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
return
arg
+
1
;
return
arg
+
1
;
}
}
function
additionDelay
(
arg
)
{
"
use concurrent
"
var
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
3000
)
{
continue
;
}
return
arg
+
1
;
}
try
{
try
{
var
task1
=
new
taskpool
.
Task
(
additionDelay
,
100
);
let
task1
=
new
taskpool
.
Task
(
addition
,
100
);
var
task2
=
new
taskpool
.
Task
(
additionDelay
,
200
);
let
task2
=
new
taskpool
.
Task
(
addition
,
200
);
var
task3
=
new
taskpool
.
Task
(
addition
,
300
);
let
task3
=
new
taskpool
.
Task
(
addition
,
300
);
let
task4
=
new
taskpool
.
Task
(
addition
,
400
);
var
result1
=
taskpool
.
execute
(
task1
);
let
task5
=
new
taskpool
.
Task
(
addition
,
500
);
var
result2
=
taskpool
.
execute
(
task2
);
let
task6
=
new
taskpool
.
Task
(
addition
,
600
);
var
result3
=
taskpool
.
execute
(
task3
);
let
result1
=
taskpool
.
execute
(
task1
);
var
start
=
new
Date
().
getTime
();
let
result2
=
taskpool
.
execute
(
task2
);
while
(
new
Date
().
getTime
()
-
start
<
1000
)
{
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
;
continue
;
}
}
taskpool
.
cancel
(
task6
);
taskpool
.
cancel
(
task5
);
taskpool
.
cancel
(
task4
);
taskpool
.
cancel
(
task3
);
taskpool
.
cancel
(
task3
);
taskpool
.
cancel
(
task
3
);
taskpool
.
cancel
(
task
2
);
}
}
catch
(
e
)
{
catch
(
e
)
{
expect
(
e
.
toString
()).
assertEqual
(
expect
(
e
.
toString
()).
assertEqual
(
...
@@ -1427,168 +1379,145 @@ describe('ActsAbilityTest', function () {
...
@@ -1427,168 +1379,145 @@ describe('ActsAbilityTest', function () {
})
})
/**
/**
* @tc.number : TaskPoolTestClass0
59
* @tc.number : TaskPoolTestClass0
62
* @tc.name : Async Function Cancel task
* @tc.name : Async Function Cancel task
Group
* @tc.desc : Cancel
all tasks in sequence
* @tc.desc : Cancel
the taskGroup in progress
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass0
59
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass0
62
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
return
arg
+
1
;
let
start
=
new
Date
().
getTime
();
}
while
(
new
Date
().
getTime
()
-
start
<
2000
)
{
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
;
continue
;
}
}
return
arg
+
1
;
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
"
);
}
}
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
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass06
0
* @tc.number : TaskPoolTestClass06
3
* @tc.name :
Sync Function Cancel task
* @tc.name :
Async Function Cancel taskGroup
* @tc.desc : Cancel
all tasks in sequence
* @tc.desc : Cancel
the taskGroup that have not been executed
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass06
0
'
,
0
,
function
(
done
)
{
it
(
'
TaskPoolTestClass06
3
'
,
0
,
async
function
(
done
)
{
function
addition
(
arg
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
let
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
2000
)
{
continue
;
}
return
arg
+
1
;
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
{
try
{
var
task1
=
new
taskpool
.
Task
(
addition
,
100
);
let
taskGroup
=
new
taskpool
.
TaskGroup
();
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
;
}
taskpool
.
cancel
(
task6
);
taskpool
.
cancel
(
taskGroup
);
taskpool
.
cancel
(
task5
);
}
catch
(
e
)
{
taskpool
.
cancel
(
task4
);
taskpool
.
cancel
(
task3
);
taskpool
.
cancel
(
task2
);
}
catch
(
e
)
{
expect
(
e
.
toString
()).
assertEqual
(
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
();
done
();
})
})
/**
/**
* @tc.number : TaskPoolTestClass06
1
* @tc.number : TaskPoolTestClass06
5
* @tc.name :
Sync Function Cancel task
* @tc.name :
Async Function Cancel taskGroup
* @tc.desc :
Test Simultaneous use taskpool and worker
* @tc.desc :
Cancel the executed taskGroup
* @tc.size : MEDIUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.type : Function
* @tc.level : Level 0
* @tc.level : Level 0
*/
*/
it
(
'
TaskPoolTestClass061
'
,
0
,
async
function
(
done
)
{
it
(
'
TaskPoolTestClass065
'
,
0
,
async
function
(
done
)
{
function
testTaskPool
()
{
function
printArgs
(
args
)
{
function
addition
(
arg
)
{
"
use concurrent
"
"
use concurrent
"
return
args
;
return
arg
+
1
;
}
}
function
additionDelay
(
arg
)
{
"
use concurrent
"
var
start
=
new
Date
().
getTime
();
while
(
new
Date
().
getTime
()
-
start
<
3000
)
{
continue
;
}
return
arg
+
1
;
}
try
{
let
taskGroup1
=
new
taskpool
.
TaskGroup
();
var
task1
=
new
taskpool
.
Task
(
additionDelay
,
10
0
);
taskGroup1
.
addTask
(
printArgs
,
1
0
);
var
task2
=
new
taskpool
.
Task
(
additionDelay
,
20
0
);
taskGroup1
.
addTask
(
printArgs
,
2
0
);
var
task3
=
new
taskpool
.
Task
(
addition
,
30
0
);
taskGroup1
.
addTask
(
printArgs
,
3
0
);
taskpool
.
execute
(
task1
)
let
taskGroup2
=
new
taskpool
.
TaskGroup
();
taskpool
.
execute
(
task2
)
let
task1
=
new
taskpool
.
Task
(
printArgs
,
100
);
taskpool
.
execute
(
task3
)
let
task2
=
new
taskpool
.
Task
(
printArgs
,
200
);
let
task3
=
new
taskpool
.
Task
(
printArgs
,
300
);
var
start
=
new
Date
().
getTime
();
taskGroup2
.
addTask
(
task1
);
while
(
new
Date
().
getTime
()
-
start
<
1000
)
{
taskGroup2
.
addTask
(
task2
);
continue
;
taskGroup2
.
addTask
(
task3
);
}
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
"
)
taskpool
.
execute
(
taskGroup1
);
let
res
=
0
taskpool
.
execute
(
taskGroup2
);
let
flag
=
false
ss
.
onexit
=
function
()
{
setTimeout
(()
=>
{
flag
=
true
try
{
res
++
taskpool
.
cancel
(
taskGroup1
);
}
}
catch
(
e
)
{
testTaskPool
();
expect
(
e
.
toString
()).
assertEqual
(
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
"
BusinessError: The task group does not exist when it is canceled, taskpool:: can not find the taskGroup
"
);
ss
.
terminate
();
}
}
},
3000
);
while
(
!
flag
)
{
await
promiseCase
()
}
expect
(
res
).
assertEqual
(
1
)
done
();
done
();
})
})
})
})
}
}
\ No newline at end of file
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
浏览文件 @
02f45609
...
@@ -2146,7 +2146,7 @@ describe('threadWorkerTest', function () {
...
@@ -2146,7 +2146,7 @@ describe('threadWorkerTest', function () {
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_016.js
"
);
let
ss
=
new
worker
.
ThreadWorker
(
"
entry/ets/workers/newworker_016.js
"
);
let
array
=
[]
let
array
=
[]
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
array
[
i
]
=
CreateArray
(
i
,
6
2
);
array
[
i
]
=
CreateArray
(
i
,
6
5
);
}
}
let
res
=
0
;
let
res
=
0
;
...
@@ -2172,7 +2172,7 @@ describe('threadWorkerTest', function () {
...
@@ -2172,7 +2172,7 @@ describe('threadWorkerTest', function () {
while
(
!
isTerminate
)
{
while
(
!
isTerminate
)
{
await
promiseCase
();
await
promiseCase
();
}
}
expect
(
res
).
assertEqual
(
6
2
0
)
expect
(
res
).
assertEqual
(
6
5
0
)
done
();
done
();
})
})
...
...
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
浏览文件 @
02f45609
...
@@ -1446,7 +1446,7 @@ describe('WorkerTest', function () {
...
@@ -1446,7 +1446,7 @@ describe('WorkerTest', function () {
let
ss
=
new
worker
.
Worker
(
"
entry/ets/workers/worker_016.js
"
);
let
ss
=
new
worker
.
Worker
(
"
entry/ets/workers/worker_016.js
"
);
let
array
=
[]
let
array
=
[]
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
array
[
i
]
=
CreateArray
(
i
,
6
2
);
array
[
i
]
=
CreateArray
(
i
,
6
5
);
}
}
let
res
=
0
;
let
res
=
0
;
...
@@ -1472,7 +1472,7 @@ describe('WorkerTest', function () {
...
@@ -1472,7 +1472,7 @@ describe('WorkerTest', function () {
while
(
!
isTerminate
)
{
while
(
!
isTerminate
)
{
await
promiseCase
();
await
promiseCase
();
}
}
expect
(
res
).
assertEqual
(
6
2
0
)
expect
(
res
).
assertEqual
(
6
5
0
)
done
();
done
();
})
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录