Explorar o código

Use Time::Mock to speed up waiter test execution

It's a bit unstable, so we need to watch the trial test reports to see
whether this is a reliable method. In order to even use it in the first
place, we opened up the intervals and expectations on the existing tests
significantly. This commit can be easily reverted; all it means is that
tests will take longer to run.
Daniel Gempesaw %!s(int64=10) %!d(string=hai) anos
pai
achega
da70bf4cf3
Modificáronse 3 ficheiros con 9 adicións e 6 borrados
  1. 1 0
      cpanfile
  2. 1 1
      lib/Selenium/Waiter.pm
  3. 7 5
      t/Waiter.t

+ 1 - 0
cpanfile

@@ -42,6 +42,7 @@ on 'test' => sub {
   requires "Test::LWP::UserAgent" => "0";
   requires "Test::More" => "0";
   requires "Test::Warn" => "0";
+  requires "Time::Mock" => "0";
   requires "lib" => "0";
 };
 

+ 1 - 1
lib/Selenium/Waiter.pm

@@ -45,7 +45,7 @@ and return control to you at that point.
 
 PLEASE check the return value before proceeding, as we unwisely
 suppress any attempts your BLOCK may make to die or croak. The BLOCK
-you pass is called in a L<try/Try::Tiny>, and if any of the
+you pass is called in a L<Try::Tiny/try>, and if any of the
 invocations of your function throw and the BLOCK never becomes true,
 we'll carp exactly once at the end immediately before returning
 false. We overwrite the death message from each iteration, so at the

+ 7 - 5
t/Waiter.t

@@ -5,14 +5,14 @@ use warnings;
 use Test::More;
 use Test::Warn;
 use Test::Fatal;
+use Time::Mock throttle => 100;
 use Selenium::Waiter;
 
-
 SIMPLE_WAIT: {
     my $ret;
-    waits_ok( sub { $ret = wait_until { 1 } }, '<', 2, 'immediately true returns quickly' );
+    waits_ok( sub { $ret = wait_until { 1 } }, '<', 5, 'immediately true returns quickly' );
     ok($ret == 1, 'return value for a true wait_until is passed up');
-    waits_ok( sub { $ret = wait_until { 0 } timeout => 3 }, '>', 2, 'never true expires the timeout' );
+    waits_ok( sub { $ret = wait_until { 0 } }, '>', 25, 'never true expires the timeout' );
     ok($ret eq '', 'return value for a false wait is an empty string');
 }
 
@@ -23,10 +23,10 @@ EVENTUALLY: {
     $ret = 0;
     my %opts = ( interval => 2, timeout => 5 );
     waits_ok(
-        sub { wait_until { $ret++; 0 } %opts }, '>', 5,
+        sub { wait_until { $ret++; 0 } %opts }, '>', 4,
         'timeout is respected'
     );
-    ok($ret == 3, 'interval option changes iteration speed');
+    ok(1 <= $ret && $ret <= 3, 'interval option changes iteration speed');
 }
 
 EXCEPTIONS: {
@@ -34,6 +34,8 @@ EXCEPTIONS: {
     warning_is { wait_until { die 'caught!' } %opts } 'caught!',
       'exceptions usually only warn once';
 
+    # This test is flaky when accelerated, so let's slow it down.
+    Time::Mock->throttle(1);
     my %debug = ( debug => 1, %opts );
     warnings_are { wait_until { die 'caught!' } %debug } ['caught!', 'caught!'],
       'exceptions warn repreatedly when in debug mode';