[Rt-commit] rt branch, 4.4-trunk, updated. rt-4.4.4-100-g0379119583

? sunnavy sunnavy at bestpractical.com
Tue Apr 28 16:28:01 EDT 2020


The branch, 4.4-trunk has been updated
       via  0379119583b52c0098bfabf9bb1c964f86af4af2 (commit)
       via  1f2abd3e83ef7cede1788560cb31140b7792d209 (commit)
      from  30486256d17b0eceac05b0a9487b0604c1a2fae9 (commit)

Summary of changes:
 lib/RT/Test.pm               | 37 +++++++++++++++++++++++++++++++++++++
 t/externalstorage/basic.t    |  2 +-
 t/externalstorage/encoding.t |  2 +-
 3 files changed, 39 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit 1f2abd3e83ef7cede1788560cb31140b7792d209
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Apr 25 01:57:14 2020 +0800

    Avoid running multiple rt-externalize-attachments simultaneously in tests
    
    rt-externalize-attachments does nothing and silently quits when there is
    another process running. Because of it, some tests could fail in
    t/externalstorage/basic.t and t/externalstorage/encoding.t
    
    This commit makes current test wait(at most 100s) when another test is
    running the same command.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 9c2d58dcdc..d7199d6b0b 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1798,6 +1798,43 @@ sub done_testing {
     $builder->done_testing(@_);
 }
 
+# Some utilities must only run one process at a time, so they check
+# for other running processes and quit if another is found. In parallel
+# test mode, this can cause test failures if two tests happen to run at
+# the same time.
+
+# This test helper checks for a running process, and if found sleeps and
+# tries again for a short time rather than immediately failing.
+
+sub run_singleton_command {
+    my $self    = shift;
+    my $command = shift;
+    my @args    = @_;
+
+    my $dir = "$tmp{'directory'}/../singleton";
+    mkdir $dir unless -e $dir;
+
+    my $flag = $command;
+    $flag =~ s!/!-!g;
+    $flag = "$dir/$flag";
+
+    for ( 1 .. 100 ) {
+        if ( -e $flag ) {
+            sleep 1;
+        }
+        else {
+            open my $fh, '>', $flag or die $!;
+            close $fh;
+            last;
+        }
+    }
+
+    my $ret = !system( $command, @args );
+    unlink $flag;
+
+    return $ret;
+}
+
 END {
     my $Test = RT::Test->builder;
     return if $Test->{Original_Pid} != $$;
diff --git a/t/externalstorage/basic.t b/t/externalstorage/basic.t
index 2fc55288aa..1c88589c84 100644
--- a/t/externalstorage/basic.t
+++ b/t/externalstorage/basic.t
@@ -64,7 +64,7 @@ ok !<$dir/*>, "Attachments directory is empty";
 
 ok -e 'sbin/rt-externalize-attachments', "Found rt-externalize-attachments script";
 ok -x 'sbin/rt-externalize-attachments', "rt-externalize-attachments is executable";
-ok !system('sbin/rt-externalize-attachments'), "rt-externalize-attachments ran successfully";
+ok( RT::Test->run_singleton_command('sbin/rt-externalize-attachments'), "rt-externalize-attachments ran successfully" );
 
 @attachs = @{ $ticket->Transactions->First->Attachments->ItemsArrayRef };
 is $attachs[1]->Content, 'test', "Can still get the text part content";
diff --git a/t/externalstorage/encoding.t b/t/externalstorage/encoding.t
index 3b1de6e7e6..667a487d78 100644
--- a/t/externalstorage/encoding.t
+++ b/t/externalstorage/encoding.t
@@ -32,7 +32,7 @@ is scalar @attachments, 1, "Found one attachment";
 is $attachments[0]->ContentType, "text/plain", "Found the text part";
 is $attachments[0]->Content, $non_english_text, "Can get the text part content";
 
-ok !system('sbin/rt-externalize-attachments'), "rt-externalize-attachments ran successfully";
+ok( RT::Test->run_singleton_command('sbin/rt-externalize-attachments'), "rt-externalize-attachments ran successfully" );
 
 @attachments = @{ $ticket->Transactions->First->Attachments->ItemsArrayRef };
 is scalar @attachments, 1, "Found one attachment";

commit 0379119583b52c0098bfabf9bb1c964f86af4af2
Merge: 30486256d1 1f2abd3e83
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 29 04:27:18 2020 +0800

    Merge branch '4.4/test-singleton-command' into 4.4-trunk


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


More information about the rt-commit mailing list