【问题标题】:Timing out tests in a Perl test harnessPerl 测试工具中的超时测试
【发布时间】:2014-09-14 23:52:21
【问题描述】:

如何让 Perl 测试工具中的挂起测试超时?

我尝试使用Test::Timer 模块,但我似乎无法使其与TAP::Harness 很好地链接,以便为每个测试嵌入超时功能。另外,我不想测试一些代码是否需要x 时间才能完成,我只想运行我的测试并超时,以防它们因任何原因挂起。

【问题讨论】:

    标签: perl tap-harness


    【解决方案1】:

    最近有a similar question on PerlMonks

    安装Time::Limit

    此模块将允许您为单个测试文件设置时间限制:

    use Test::More;
    use Time::Limit "30";   # 30 seconds, quote marks are necessary!
    

    或者设置运行整个测试套件的总体时间限制:

    prove -MTime::Limit=120 t/*.t
    

    如果你使用forkprove而不是prove,那么你需要时间限制器来杀死整个进程组:

    forkprove -MTime::Limit=-group,120 t/*.t
    

    【讨论】:

    • 这似乎对我不起作用。我应该提到我正在尝试在 Windows 机器上使用它。到目前为止我得到的是sub test_with_timeout { my $current_test=shift || die "Must provide a test"; my $harness = shift || die "Must provide a harness"; my $timeout=shift || -1; $SIG{ALRM} = sub { print "Timeout after $timeout seconds\n"; die; }; # print "Timeout is $timeout seconds\n\n"; alarm($timeout); my $result=$harness->runtests($current_test); alarm(0); return $result; }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多