Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
dcf48f27
I
incubator-echarts
项目概览
半栈学徒
/
incubator-echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
incubator-echarts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dcf48f27
编写于
5月 10, 2021
作者:
P
pissang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(visual): use threads in cli instead of server
上级
568bf008
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
52 deletion
+42
-52
test/runTest/cli.js
test/runTest/cli.js
+1
-1
test/runTest/server.js
test/runTest/server.js
+41
-51
未找到文件。
test/runTest/cli.js
浏览文件 @
dcf48f27
...
...
@@ -40,7 +40,7 @@ program
.
option
(
'
--expected <expected>
'
,
'
Expected version
'
)
.
option
(
'
--actual <actual>
'
,
'
Actual version
'
)
.
option
(
'
--renderer <renderer>
'
,
'
svg/canvas renderer
'
)
.
option
(
'
--threads
'
,
'
How many threads to run concurrently
'
)
.
option
(
'
--threads
<threads>
'
,
'
How many threads to run concurrently
'
)
.
option
(
'
--no-save
'
,
'
Don
\'
t save result
'
)
.
option
(
'
--dir <dir>
'
,
'
Out dir
'
);
...
...
test/runTest/server.js
浏览文件 @
dcf48f27
...
...
@@ -63,15 +63,15 @@ function serve() {
};
};
let
runningThread
s
=
[]
;
let
runningThread
;
let
pendingTests
;
let
running
=
false
;
function
stopRunningTests
()
{
if
(
runningThread
s
)
{
runningThread
s
.
forEach
(
thread
=>
thread
.
kill
()
);
runningThread
s
=
[]
;
if
(
runningThread
)
{
runningThread
.
kill
(
);
runningThread
=
null
;
}
if
(
pendingTests
)
{
pendingTests
.
forEach
(
testOpt
=>
{
if
(
testOpt
.
status
===
'
pending
'
)
{
...
...
@@ -93,8 +93,7 @@ class Thread {
fork
(
extraArgs
)
{
let
p
=
fork
(
path
.
join
(
__dirname
,
'
cli.js
'
),
[
'
--tests
'
,
this
.
tests
.
map
(
testOpt
=>
testOpt
.
name
).
join
(
'
,
'
),
'
--tests
'
,
this
.
tests
.
map
(
testOpt
=>
testOpt
.
name
).
join
(
'
,
'
),
...
extraArgs
]);
this
.
p
=
p
;
...
...
@@ -131,9 +130,12 @@ function startTests(testsNameList, socket, {
console
.
log
(
'
Received:
'
,
testsNameList
.
join
(
'
,
'
));
threadsCount
=
threadsCount
||
1
;
stopRunningTests
();
return
new
Promise
(
resolve
=>
{
if
(
!
runningThread
)
{
resolve
();
}
pendingTests
=
getTestsList
().
filter
(
testOpt
=>
{
return
testsNameList
.
includes
(
testOpt
.
name
);
});
...
...
@@ -147,7 +149,7 @@ function startTests(testsNameList, socket, {
// Save status immediately
saveTestsList
();
if
(
running
)
{
if
(
running
Thread
)
{
socket
.
emit
(
'
update
'
,
{
tests
:
getTestsList
(),
running
:
true
...
...
@@ -155,47 +157,32 @@ function startTests(testsNameList, socket, {
}
}
let
runningCount
=
0
;
function
onExit
()
{
runningCount
--
;
if
(
runningCount
===
0
)
{
runningThreads
=
[];
resolve
();
}
runningThread
=
null
;
resolve
();
}
function
onUpdate
()
{
// Merge tests.
if
(
running
&&
!
noSave
)
{
if
(
running
Thread
&&
!
noSave
)
{
socket
.
emit
(
'
update
'
,
{
tests
:
getTestsList
(),
running
:
true
});
}
}
threadsCount
=
Math
.
min
(
threadsCount
,
pendingTests
.
length
);
// Assigning tests to threads
runningThreads
=
new
Array
(
threadsCount
).
fill
(
0
).
map
(()
=>
new
Thread
()
);
for
(
let
i
=
0
;
i
<
pendingTests
.
length
;
i
++
)
{
runningThreads
[
i
%
threadsCount
].
tests
.
push
(
pendingTests
[
i
]);
}
for
(
let
i
=
0
;
i
<
threadsCount
;
i
++
)
{
runningThreads
[
i
].
onExit
=
onExit
;
runningThreads
[
i
].
onUpdate
=
onUpdate
;
runningThreads
[
i
].
fork
([
'
--speed
'
,
replaySpeed
||
5
,
'
--actual
'
,
actualVersion
,
'
--expected
'
,
expectedVersion
,
'
--renderer
'
,
renderer
||
''
,
'
--dir
'
,
getResultBaseDir
(),
...(
noHeadless
?
[
'
--no-headless
'
]
:
[]),
...(
noSave
?
[
'
--no-save
'
]
:
[])
]);
runningCount
++
;
}
// If something bad happens and no proccess are started successfully
if
(
runningCount
===
0
)
{
resolve
();
}
runningThread
.
tests
=
pendingTests
.
slice
();
runningThread
.
onExit
=
onExit
;
runningThread
.
onUpdate
=
onUpdate
;
runningThread
.
fork
([
'
--speed
'
,
replaySpeed
||
5
,
'
--actual
'
,
actualVersion
,
'
--expected
'
,
expectedVersion
,
'
--renderer
'
,
renderer
||
''
,
'
--threads
'
,
threadsCount
,
'
--dir
'
,
getResultBaseDir
(),
...(
noHeadless
?
[
'
--no-headless
'
]
:
[]),
...(
noSave
?
[
'
--no-save
'
]
:
[])
]);
});
}
...
...
@@ -234,13 +221,15 @@ async function start() {
nightlyVersions
.
unshift
(
'
local
'
);
io
.
of
(
'
/client
'
).
on
(
'
connect
'
,
async
socket
=>
{
let
isAborted
=
false
;
function
abortTests
()
{
if
(
!
running
)
{
if
(
!
running
Thread
)
{
return
;
}
isAborted
=
true
;
stopRunningTests
();
io
.
of
(
'
/client
'
).
emit
(
'
abort
'
);
running
=
false
;
}
socket
.
on
(
'
syncRunConfig
'
,
async
({
...
...
@@ -277,12 +266,12 @@ async function start() {
}
await
updateTestsList
(
_currentTestHash
=
getRunHash
(
_currentRunConfig
),
!
running
// Set to unsettled if not running
!
running
Thread
// Set to unsettled if not running
);
socket
.
emit
(
'
update
'
,
{
tests
:
getTestsList
(),
running
:
runningThreads
.
length
>
0
running
:
!!
runningThread
});
});
...
...
@@ -308,17 +297,16 @@ async function start() {
});
socket
.
on
(
'
run
'
,
async
data
=>
{
stopRunningTests
();
isAborted
=
false
;
// Create runningThread immediately. In case abort happens.
runningThread
=
new
Thread
();
let
startTime
=
Date
.
now
();
running
=
true
;
await
prepareEChartsLib
(
data
.
expectedVersion
);
// Expected version.
await
prepareEChartsLib
(
data
.
actualVersion
);
// Version to test
if
(
!
running
)
{
// If it is aborted when downloading echarts lib.
return
;
}
// TODO Should broadcast to all sockets.
try
{
if
(
!
checkStoreVersion
(
data
))
{
...
...
@@ -343,14 +331,13 @@ async function start() {
console
.
error
(
e
);
}
if
(
running
)
{
if
(
!
isAborted
)
{
console
.
log
(
'
Finished
'
);
io
.
of
(
'
/client
'
).
emit
(
'
finish
'
,
{
time
:
Date
.
now
()
-
startTime
,
count
:
data
.
tests
.
length
,
threads
:
data
.
threads
});
running
=
false
;
}
else
{
console
.
log
(
'
Aborted!
'
);
...
...
@@ -385,6 +372,9 @@ async function start() {
}
});
socket
.
on
(
'
runSingle
'
,
async
data
=>
{
stopRunningTests
();
runningThread
=
new
Thread
();
try
{
await
startTests
([
data
.
testName
],
socket
,
{
noHeadless
:
true
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录