Mercurial > hg > nginx-tests
changeset 290:f781b087b7aa
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).
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Thu, 30 May 2013 07:38:23 +0400 |
parents | cbd4f6eca676 |
children | 03d5be12bc3b |
files | lib/Test/Nginx.pm |
diffstat | 1 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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($;) {