Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9006913b
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9006913b
编写于
8月 06, 2016
作者:
F
Felix Rath
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add warning timeout for tests that run >1min
this makes it easier to identify hanging tests
上级
ecdd51b7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
1 deletion
+47
-1
src/libtest/lib.rs
src/libtest/lib.rs
+47
-1
未找到文件。
src/libtest/lib.rs
浏览文件 @
9006913b
...
...
@@ -42,6 +42,7 @@
#![feature(staged_api)]
#![feature(question_mark)]
#![feature(panic_unwind)]
#![feature(mpsc_recv_timeout)]
extern
crate
getopts
;
extern
crate
term
;
...
...
@@ -73,6 +74,8 @@
use
std
::
thread
;
use
std
::
time
::{
Instant
,
Duration
};
const
TEST_WARN_TIMEOUT_S
:
u64
=
60
;
// to be used by rustc to compile tests in libtest
pub
mod
test
{
pub
use
{
Bencher
,
TestName
,
TestResult
,
TestDesc
,
TestDescAndFn
,
TestOpts
,
TrFailed
,
...
...
@@ -592,6 +595,10 @@ pub fn write_result(&mut self, result: &TestResult) -> io::Result<()> {
}
}
pub
fn
write_timeout
(
&
mut
self
,
desc
:
&
TestDesc
)
->
io
::
Result
<
()
>
{
self
.write_plain
(
&
format!
(
"test {} has been running for over {} seconds
\n
"
,
desc
.name
,
TEST_WARN_TIMEOUT_S
))
}
pub
fn
write_log
(
&
mut
self
,
test
:
&
TestDesc
,
result
:
&
TestResult
)
->
io
::
Result
<
()
>
{
match
self
.log_out
{
None
=>
Ok
(()),
...
...
@@ -709,6 +716,7 @@ fn callback<T: Write>(event: &TestEvent, st: &mut ConsoleTestState<T>) -> io::Re
match
(
*
event
)
.clone
()
{
TeFiltered
(
ref
filtered_tests
)
=>
st
.write_run_start
(
filtered_tests
.len
()),
TeWait
(
ref
test
,
padding
)
=>
st
.write_test_start
(
test
,
padding
),
TeTimeout
(
ref
test
)
=>
st
.write_timeout
(
test
),
TeResult
(
test
,
result
,
stdout
)
=>
{
st
.write_log
(
&
test
,
&
result
)
?
;
st
.write_result
(
&
result
)
?
;
...
...
@@ -830,6 +838,7 @@ enum TestEvent {
TeFiltered
(
Vec
<
TestDesc
>
),
TeWait
(
TestDesc
,
NamePadding
),
TeResult
(
TestDesc
,
TestResult
,
Vec
<
u8
>
),
TeTimeout
(
TestDesc
),
}
pub
type
MonitorMsg
=
(
TestDesc
,
TestResult
,
Vec
<
u8
>
);
...
...
@@ -838,6 +847,9 @@ enum TestEvent {
fn
run_tests
<
F
>
(
opts
:
&
TestOpts
,
tests
:
Vec
<
TestDescAndFn
>
,
mut
callback
:
F
)
->
io
::
Result
<
()
>
where
F
:
FnMut
(
TestEvent
)
->
io
::
Result
<
()
>
{
use
std
::
collections
::
HashMap
;
use
std
::
sync
::
mpsc
::
RecvTimeoutError
;
let
mut
filtered_tests
=
filter_tests
(
opts
,
tests
);
if
!
opts
.bench_benchmarks
{
filtered_tests
=
convert_benchmarks_to_tests
(
filtered_tests
);
...
...
@@ -867,6 +879,8 @@ fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F) ->
let
(
tx
,
rx
)
=
channel
::
<
MonitorMsg
>
();
let
mut
running_tests
:
HashMap
<
TestDesc
,
Duration
>
=
HashMap
::
new
();
while
pending
>
0
||
!
remaining
.is_empty
()
{
while
pending
<
concurrency
&&
!
remaining
.is_empty
()
{
let
test
=
remaining
.pop
()
.unwrap
();
...
...
@@ -876,11 +890,43 @@ fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F) ->
// that hang forever.
callback
(
TeWait
(
test
.desc
.clone
(),
test
.testfn
.padding
()))
?
;
}
running_tests
.insert
(
test
.desc
.clone
(),
Duration
::
from_secs
(
TEST_WARN_TIMEOUT_S
));
run_test
(
opts
,
!
opts
.run_tests
,
test
,
tx
.clone
());
pending
+=
1
;
}
let
(
desc
,
result
,
stdout
)
=
rx
.recv
()
.unwrap
();
let
mut
res
;
if
let
Some
(
min_timeout
)
=
running_tests
.values
()
.min
()
.cloned
()
{
loop
{
let
before
=
Instant
::
now
();
res
=
rx
.recv_timeout
(
min_timeout
);
let
elapsed
=
Instant
::
now
()
-
before
;
let
mut
to_remove
=
Vec
::
new
();
for
(
desc
,
time_left
)
in
&
mut
running_tests
{
if
*
time_left
>=
elapsed
{
*
time_left
-=
elapsed
;
}
else
{
to_remove
.push
(
desc
.clone
());
callback
(
TeTimeout
(
desc
.clone
()))
?
;
}
}
for
rem
in
to_remove
{
running_tests
.remove
(
&
rem
);
}
if
res
!=
Err
(
RecvTimeoutError
::
Timeout
)
{
break
;
}
}
}
else
{
res
=
rx
.recv
()
.map_err
(|
_
|
RecvTimeoutError
::
Disconnected
);
}
let
(
desc
,
result
,
stdout
)
=
res
.unwrap
();
running_tests
.remove
(
&
desc
);
if
concurrency
!=
1
{
callback
(
TeWait
(
desc
.clone
(),
PadNone
))
?
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录