diff --git a/lib/Test/Smoke/App/HandleQueue.pm b/lib/Test/Smoke/App/HandleQueue.pm index f4a3793..201328a 100644 --- a/lib/Test/Smoke/App/HandleQueue.pm +++ b/lib/Test/Smoke/App/HandleQueue.pm @@ -71,20 +71,22 @@ sub new { my $class = shift; my $self = $class->SUPER::new(@_); - $self->{_poster} = Test::Smoke::Poster->new( - $self->option('poster') => $self->options, - - # We will need to fake 'ddir' in order to get the reports from the - # archive - ddir => $self->option('adir'), - v => $self->option('verbose'), - ); - $self->{_queue} = Test::Smoke::PostQueue->new( - adir => $self->option('adir'), - qfile => $self->option('qfile'), - v => $self->option('verbose'), - poster => $self->poster, - ); + if (defined($self->option('qfile'))) { + $self->{_poster} = Test::Smoke::Poster->new( + $self->option('poster') => $self->options, + + # We will need to fake 'ddir' in order to get the reports from the + # archive + ddir => $self->option('adir'), + v => $self->option('verbose'), + ); + $self->{_queue} = Test::Smoke::PostQueue->new( + adir => $self->option('adir'), + qfile => $self->option('qfile'), + v => $self->option('verbose'), + poster => $self->poster, + ); + } return $self; } @@ -98,6 +100,7 @@ Try to send all items in the queue and remove items that are no longer in the ar sub run { my $self = shift; + return unless defined($self->{_queue}); $self->queue->handle(); $self->queue->purge(); } diff --git a/t/app/170-handlequeue.t b/t/app/170-handlequeue.t index e1e346c..18b2036 100644 --- a/t/app/170-handlequeue.t +++ b/t/app/170-handlequeue.t @@ -10,6 +10,7 @@ use File::Path qw< mkpath >; use Test::Smoke::App::Options; use Test::Smoke::App::HandleQueue; +use Test::Smoke::PostQueue; my $commit = '9d4a846c758608a6297babf9582967e036edfa1f'; my $non_commit = '9d4a846c758608a6297babf9582967e036edfa20'; @@ -21,6 +22,27 @@ my $qfile = catfile($tempdir, "${prefix}.qfile"); prepare_archive($adir, $commit); prepare_queue($qfile, $commit, $non_commit); +# Test that HandleQueue works gracefully when qfile is not configured. +# This must run first, before any PostQueue singleton is created. +{ + local @ARGV = ( + '--adir', $adir, + '--smokedb_url', 'http://localhost/report', + '--poster' => 'HTTP::Tiny', + # no --qfile + ); + my $app; + eval { + $app = Test::Smoke::App::HandleQueue->new( + Test::Smoke::App::Options->handlequeue_config + ); + }; + is($@, '', "HandleQueue->new() does not die when qfile is not configured"); + isa_ok($app, 'Test::Smoke::App::HandleQueue'); + + my $result = eval { $app->run(); 1 }; + is($@, '', "HandleQueue->run() does not die when qfile is not configured"); +} { no warnings 'redefine';