Skip to content

Commit

Permalink
Avoid a race condition in crypt testing
Browse files Browse the repository at this point in the history
Test::Warn fails us here because it only captures the first line of a
multi-line warning.  Opening up the debug log and searching over it
leads to race conditions, as the error we're looking for may not have
been flushed to disk by the time we read it.

Instead, use a simple __WARN__ handler to look for the desired warning.
  • Loading branch information
alexmv committed Mar 13, 2014
1 parent 8f73c12 commit 4b6ce71
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions t/crypt/no-signer-address.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

use RT::Test::GnuPG
tests => 6,
tests => undef,
gnupg_options => {
passphrase => 'rt-test',
'trust-model' => 'always',
Expand All @@ -19,18 +19,24 @@ my $queue;
ok !$queue->CorrespondAddress, 'address not set';
}

use Test::Warn;
warnings_like {
my $ticket = RT::Ticket->new( RT->SystemUser );
my ($status, undef, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
Requestor => 'root@localhost',
);
ok $status, "created ticket" or diag "error: $msg";
# We don't use Test::Warn here, because it apparently only captures up
# to the first newline -- and the meat of this message is on the fourth
# line.
my @warnings;
local $SIG{__WARN__} = sub {
push @warnings, "@_";
};

my $ticket = RT::Ticket->new( RT->SystemUser );
my ($status, undef, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
Requestor => 'root@localhost',
);
ok( $status, "created ticket" ) or diag "error: $msg";

my $log = RT::Test->file_content([RT::Test->temp_directory, 'rt.debug.log']);
like $log, qr{secret key not available}, 'error in the log';
unlike $log, qr{Scrip .*? died}m, "scrip didn't die";
} [qr{gpg: keyring .*? created}];
is( scalar @warnings, 1, "Got a warning" );
like( $warnings[0], qr{signing failed: secret key not available},
"Found warning of no secret key");

done_testing;

0 comments on commit 4b6ce71

Please sign in to comment.