[Rt-commit] rt branch, 4.4/test-singleton-command, created. rt-4.4.4-99-g57b57a2844
? sunnavy
sunnavy at bestpractical.com
Fri Apr 24 14:38:14 EDT 2020
The branch, 4.4/test-singleton-command has been created
at 57b57a284412f06e063d8d7c1e7d48dd58cb5ede (commit)
- Log -----------------------------------------------------------------
commit 57b57a284412f06e063d8d7c1e7d48dd58cb5ede
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..478a6fd215 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1798,6 +1798,35 @@ sub done_testing {
$builder->done_testing(@_);
}
+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";
-----------------------------------------------------------------------
More information about the rt-commit
mailing list