# HG changeset patch # User Vladimir Homutov # Date 1369885103 -14400 # Node ID f781b087b7aa1e9dc90d780bb1db296a1b12ea99 # Parent cbd4f6eca676be4f724bd7da2fbeb129e1a17452 Tests: fixed possible test suite hang on exit. In some cases (for example, call of global object method in a function), test suite can hang during exit, because temporary directory holding a pid file is removed prior to executing global test object desctructor. The root cause is that the directory removal occurs in the END block (in the File::Temp package) and the order of executing destructors and END blocks is not specified in Perl. The fix is to remove temporary directory in the test object destructor explicitly and get rid of 'CLEANUP' flag in the tempdir() call. The temporary directory is removed by the means of rmtree() function, called inside an eval block to exclude the case when rmtree may abort (some versions are known to do it). diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -19,6 +19,7 @@ our %EXPORT_TAGS = ( ############################################################################### +use File::Path qw/ rmtree /; use File::Temp qw/ tempdir /; use IO::Socket; use POSIX qw/ waitpid WNOHANG /; @@ -36,8 +37,7 @@ sub new { $self->{_testdir} = tempdir( 'nginx-test-XXXXXXXXXX', - TMPDIR => 1, - CLEANUP => not $ENV{TEST_NGINX_LEAVE} + TMPDIR => 1 ) or die "Can't create temp directory: $!\n"; $self->{_testdir} =~ s!\\!/!g if $^O eq 'MSWin32'; @@ -52,6 +52,9 @@ sub DESTROY { if ($ENV{TEST_NGINX_CATLOG}) { system("cat $self->{_testdir}/error.log"); } + if (not $ENV{TEST_NGINX_LEAVE}) { + eval { rmtree($self->{_testdir}); }; + } } sub has($;) {