[Rt-commit] rt branch, 4.2/test-crypt-race-condition, created. rt-4.2.3-30-g9b123a3

Alex Vandiver alexmv at bestpractical.com
Wed Mar 12 23:21:23 EDT 2014


The branch, 4.2/test-crypt-race-condition has been created
        at  9b123a35d4f8c7ad0974ec9cce7b4a26b6b53eb8 (commit)

- Log -----------------------------------------------------------------
commit 9b123a35d4f8c7ad0974ec9cce7b4a26b6b53eb8
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Mar 12 23:15:59 2014 -0400

    Avoid a race condition in crypt testing
    
    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.

diff --git a/t/crypt/no-signer-address.t b/t/crypt/no-signer-address.t
index 8f4a0b1..4a812ef 100644
--- a/t/crypt/no-signer-address.t
+++ b/t/crypt/no-signer-address.t
@@ -2,7 +2,7 @@ use strict;
 use warnings;
 
 use RT::Test::GnuPG
-  tests         => 6,
+  tests         => undef,
   gnupg_options => {
     passphrase    => 'rt-test',
     'trust-model' => 'always',
@@ -19,18 +19,25 @@ 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 at 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 at 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 @warnings, 1, "Got a warning";
+diag "@warnings";
+like $warnings[0], qr{signing failed: secret key not available},
+    "Found warning of no secret key";
 
+done_testing;

-----------------------------------------------------------------------


More information about the rt-commit mailing list