简体   繁体   English

如何获得Test :: WWW :: Mechanize :: PSGI对象的“干净”克隆以进行汇总测试?

[英]How do I get a “clean” clone of a Test::WWW::Mechanize::PSGI object for aggregated tests?

I have a large test suite for Catalyst/PSGI website that takes about 40+ minutes run. 我有一个适用于Catalyst / PSGI网站的大型测试套件,运行大约40分钟以上。 I've switched it to use aggregated tests, using Test::Aggregate::Nested , and now it takes about 20+ minutes to run. 我已将其切换为使用Test :: Aggregate :: Nested的聚合测试,现在运行大约需要20多分钟。

I've been experimenting with having the test suite use the clone method from WWW::Mechanize between tests to improve performance. 我一直在尝试让测试套件使用WWW :: Mechanize之间的克隆方法来提高测试性能。

Between tests, I am cloning and "resetting" the shared $mech object like so: 在两次测试之间,我将克隆并“重置”共享的$mech对象,如下所示:

if ($orig) {

    $mech = $orig->clone();
    $mech->max_redirect(7);
    $mech->cookie_jar->clear;

} else {

    $orig = Test::WWW::Mechanize::PSGI->new( app => $app );

}

Note that Test::WWW::Mechanize::PSGI extends WWW::Mechanize. 请注意, Test :: WWW :: Mechanize :: PSGI扩展了WWW :: Mechanize。

This reduces the time it takes to run tests significantly, to under 5 minutes. 这样可以将运行测试所需的时间大大减少到5分钟以内。

But clearly this isn't enough: I still need to get a new object for specific tests, because of side-effects between tests that requires manually getting a new Test::WWW::Mechanize::PSGI object in some of the test scripts. 但是显然这还不够:我仍然需要为特定的测试获取一个新对象,因为测试之间的副作用需要在某些测试脚本中手动获取一个新的Test :: WWW :: Mechanize :: PSGI对象。 That adds another few minutes to the test time. 这又增加了几分钟的测试时间。

I consider the side-effects between tests a bug and the neet to get a fresh object in some tests to be a kluge. 我认为测试之间的副作用是错误,而在某些测试中获得新对象的必要条件则是无用的。

So my question is: what else can I do to reset the state of the object? 所以我的问题是:我还可以做什么来重置对象的状态?

It looks like the clone method aore WWW::Mechanize does not produce a pristine clone, despite the documentation. 尽管有文档,但看起来克隆方法aore WWW :: Mechanize不会产生原始克隆。 I needed to add the following, which appears to be fixing the issue for most tests: 我需要添加以下内容,这似乎可以解决大多数测试的问题:

$mech->{headers} = {};
$mech->{page_stack} = [];

FWIW, I found these by using an is_deeply test to compare the clone with a new object. FWIW,我通过使用is_deeply测试将克隆与新对象进行比较发现了它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM