diff options
Diffstat (limited to 't')
-rw-r--r-- | t/queue.t | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -1,6 +1,11 @@ -use Test::More; use Iurt::Queue; +use Test::More; + +use Cwd; +use File::stat 'stat'; +use MDK::Common qw(cat_); + $config = {}; my $media = 'core/release'; @@ -57,4 +62,46 @@ $ent = create_ent(); remove_bot_from_package($ent, $media, 'h1', 2); is_deeply $ent->{media}{$media}{bot}, [$b1, $b3] or diag explain $ent->{media}{$media}{bot}; + +chdir 't' if -d 't'; +mkdir "tmp"; +my $dir = Cwd::cwd() . "/tmp"; +my $retry_file = "${dir}/test_noarch.retry"; +unlink $retry_file; + +sub verify_retry_file { + my ($test, $present, $content, $mtime) = @_; + if ($present) { + ok(-f $retry_file, "$test - $retry_file should exist"); + } else { + ok(!-f $retry_file, "$test - $retry_file should not exist"); + return; + } + is(cat_($retry_file), $content, "$test - $retry_file should contain $content"); + if ($mtime) { + my $t = stat($retry_file)->mtime; + # Allow 5s difference if running on a very slow machine + ok($t > $mtime - 5); + ok($t < $mtime + 5); + } +} + +unlink $retry_file; +ok(schedule_next_retry({'backoff_delays' => [1000, 2000]}, $dir, 'test', 'noarch', 0), "schedule_next_retry - first failure is retried"); +verify_retry_file("schedule_next_retry - first failure is retried", 1, 1, time+1000); + +unlink $retry_file; +ok(schedule_next_retry({'backoff_delays' => [1000, 2000]}, $dir, 'test', 'noarch', 1), "schedule_next_retry - one retry left is retried"); +verify_retry_file("schedule_next_retry - one retry left is retried", 1, 2, time+2000); + +unlink $retry_file; +ok(!schedule_next_retry({'backoff_delays' => [120, 1000]}, $dir, 'test', 'noarch', 2), "schedule_next_retry - no retry left is failed"); + +unlink $retry_file; +ok(!schedule_next_retry({'backoff_delays' => []}, $dir, 'test', 'noarch', 0), "schedule_next_retry - no retry is failed"); + +unlink $retry_file; +ok(schedule_next_retry({}, $dir, 'test', 'noarch', 0), "schedule_next_retry - always retry is retried"); +verify_retry_file("schedule_next_retry - always retry is retried", 0); + done_testing(); |