X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2Flib%2FDebbugsTest.pm;h=4e510f6af3a8bcd3debcba17f800fc8c6894a661;hb=a0b230f7f24a056ba0e08f4d3ed820f6986e8202;hp=f7dbe6d8f9abb55c6fabdd11e647add589f4d358;hpb=ca224fb7bb63f74e8031d20c85df87b53d0e0219;p=debbugs.git diff --git a/t/lib/DebbugsTest.pm b/t/lib/DebbugsTest.pm index f7dbe6d..4e510f6 100644 --- a/t/lib/DebbugsTest.pm +++ b/t/lib/DebbugsTest.pm @@ -30,6 +30,8 @@ use Cwd qw(getcwd); use Debbugs::MIME qw(create_mime_message); use File::Basename qw(dirname basename); use IPC::Open3; +use IO::Handle; +use Test::More; use Params::Validate qw(validate_with :types); @@ -39,9 +41,10 @@ BEGIN{ @EXPORT = (); %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message)], + mail => [qw(num_messages_sent)], ); @EXPORT_OK = (); - Exporter::export_ok_tags(qw(configuration)); + Exporter::export_ok_tags(qw(configuration mail)); $EXPORT_TAGS{all} = [@EXPORT_OK]; } @@ -78,15 +81,19 @@ sub create_debbugs_configuration { \$gSendmail='$sendmail_tester'; \$gSpoolDir='$spool_dir'; \$gLibPath='@{[getcwd()]}/scripts'; +\$gTemplateDir='@{[getcwd()]}/templates'; +\$gWebHost='localhost'; 1; END "$spool_dir/nextnumber" => qq(1\n), - "$config_dir/Maintainers" => qq(foo Blah Bleargh \n), + "$config_dir/Maintainers" => qq(foo Blah Bleargh \nbar Bar Bleargh \n), "$config_dir/Maintainers.override" => qq(), + "$config_dir/Source_maintainers" => qq(foo Blah Bleargh \nbar Bar Bleargh \n), "$config_dir/indices/sources" => < '', + "$config_dir/pseudo-packages.maintainers" => '', ); while (my ($file,$contents) = each %files_to_create) { system('mkdir','-p',dirname($file)); @@ -146,13 +153,19 @@ sub send_message{ $ENV{LOCAL_PART} = $param{to}; my ($rfd,$wfd); my $output=''; - my $pid = open3($wfd,$rfd,$rfd,'scripts/receive.in') - or die "Unable to start receive.in: $!"; + local $SIG{PIPE} = 'IGNORE'; + local $SIG{CHLD} = sub {}; + my $pid = open3($wfd,$rfd,$rfd,'scripts/receive') + or die "Unable to start receive: $!"; print {$wfd} create_mime_message($param{headers}, - $param{body}) or die "Unable to to print to receive.in"; - close($wfd) or die "Unable to close receive.in"; - waitpid($pid,0); - my $err = $?>>8; + $param{body}) or die "Unable to to print to receive"; + close($wfd) or die "Unable to close receive"; + my $err = $? >> 8; + my $childpid = waitpid($pid,0); + if ($childpid != -1) { + $err = $? >> 8; + print STDERR "receive pid: $pid doesn't match childpid: $childpid\n" if $childpid != $pid; + } if ($err != 0 ) { my $rfh = IO::Handle->new_from_fd($rfd,'r') or die "Unable to create filehandle: $!"; $rfh->blocking(0); @@ -161,12 +174,12 @@ sub send_message{ if (not defined $rv) { print STDERR "Reading from STDOUT/STDERR would have blocked."; } - print STDERR $output; - die "receive.in failed with exit status $err"; + print STDERR $output,qq(\n); + die "receive failed with exit status $err"; } # now we should run processall to see if the message gets processed if ($param{run_processall}) { - system('scripts/processall.in') == 0 or die "processall.in failed"; + system('scripts/processall') == 0 or die "processall failed"; } } @@ -181,8 +194,10 @@ sub send_message{ END { if (defined $child_pid) { # stop the child + my $temp_exit = $?; kill(15,$child_pid); waitpid(-1,0); + $? = $temp_exit; } } @@ -219,6 +234,25 @@ sub send_message{ } } +=head2 num_messages_sent + + $SD_SIZE = num_messages_sent($SD_SIZE,2,$sendmail_dir,'2 messages have been sent properly'); + +Tests to make sure that at least a certain number of messages have +been sent since the last time this command was run. Usefull to test to +make sure that mail has been sent. + +=cut + +sub num_messages_sent { + my ($prev_size,$num_messages,$sendmail_dir,$test_name) = @_; + my $cur_size = dirsize($sendmail_dir); + ## print STDERR "sendmail: $sendmail_dir, want: $num_messages, + ## size: $cur_size, prev_size: $prev_size\n"; + ok($cur_size-$prev_size >= $num_messages, $test_name); + return $cur_size; +} + 1;