summaryrefslogtreecommitdiff
path: root/dist/Thread-Semaphore
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2014-12-03 10:53:00 +0000
committerDavid Mitchell <davem@iabyn.com>2014-12-03 10:53:00 +0000
commitc6eacdc3acc965cb069ded02e066d3c00e9385df (patch)
tree2f87a4ef60b8759702678d6cb5c3654f228a62a6 /dist/Thread-Semaphore
parent1037353b7e5ab2b2522d601c33d3c548ab4cd100 (diff)
downloadperl-c6eacdc3acc965cb069ded02e066d3c00e9385df.tar.gz
Stop test suite filling /tmp
Some test files use File::Temp in such a way that the temporary files and directories under /tmp aren't deleted at the end. On a smoker system, this can gradually accumulate thousands of entries under /tmp. The general culprits fixed by this commit are: 1) using tempfile() without the UNLINK => 1 argument; 2) Using Test::More (which uses Test::Stream), which creates a test directory in such a way that only the original parent thread will remove it; for some reason I still don't fully understand, detaching a thread rather than joining it stops this clean up happening. In the affected test files, I replaced the ->detach() with a ->join() just before exit, and the problem went away. Some tests under cpan/ are still leaky; these will be addressed upstream.
Diffstat (limited to 'dist/Thread-Semaphore')
-rw-r--r--dist/Thread-Semaphore/t/01_basic.t12
-rw-r--r--dist/Thread-Semaphore/t/04_nonblocking.t5
-rw-r--r--dist/Thread-Semaphore/t/05_force.t6
3 files changed, 15 insertions, 8 deletions
diff --git a/dist/Thread-Semaphore/t/01_basic.t b/dist/Thread-Semaphore/t/01_basic.t
index c5670bd87f..b10f7254fb 100644
--- a/dist/Thread-Semaphore/t/01_basic.t
+++ b/dist/Thread-Semaphore/t/01_basic.t
@@ -30,7 +30,9 @@ ok($st, 'New Semaphore');
my $token :shared = 0;
-threads->create(sub {
+my @threads;
+
+push @threads, threads->create(sub {
$st->down();
is($token++, 1, 'Thread 1 got semaphore');
$st->up();
@@ -39,9 +41,9 @@ threads->create(sub {
$st->down(4);
is($token, 5, 'Thread 1 done');
$sm->up();
-})->detach();
+});
-threads->create(sub {
+push @threads, threads->create(sub {
$st->down(2);
is($token++, 3, 'Thread 2 got semaphore');
$st->up();
@@ -50,7 +52,7 @@ threads->create(sub {
$st->down(4);
is($token, 5, 'Thread 2 done');
$sm->up();
-})->detach();
+});
$sm->down();
is($token++, 0, 'Main has semaphore');
@@ -69,6 +71,8 @@ $st->down();
ok(1, 'Main done');
threads::yield();
+$_->join for @threads;
+
exit(0);
# EOF
diff --git a/dist/Thread-Semaphore/t/04_nonblocking.t b/dist/Thread-Semaphore/t/04_nonblocking.t
index a4e8cd6709..d1538e8115 100644
--- a/dist/Thread-Semaphore/t/04_nonblocking.t
+++ b/dist/Thread-Semaphore/t/04_nonblocking.t
@@ -30,7 +30,7 @@ ok($st, 'New Semaphore');
my $token :shared = 0;
-threads->create(sub {
+my $thread = threads->create(sub {
ok(! $st->down_nb(), 'Semaphore unavailable to thread');
$sm->up();
@@ -42,7 +42,7 @@ threads->create(sub {
ok(! $st->down_nb(), 'Semaphore unavailable to thread');
is($token++, 1, 'Thread done');
$sm->up();
-})->detach();
+});
$sm->down(1);
is($token++, 0, 'Main has semaphore');
@@ -54,6 +54,7 @@ $st->up(4);
$sm->down();
is($token++, 2, 'Main got semaphore');
+$thread->join;
exit(0);
# EOF
diff --git a/dist/Thread-Semaphore/t/05_force.t b/dist/Thread-Semaphore/t/05_force.t
index c1ed70bbb9..8803cfa160 100644
--- a/dist/Thread-Semaphore/t/05_force.t
+++ b/dist/Thread-Semaphore/t/05_force.t
@@ -30,7 +30,7 @@ ok($st, 'New Semaphore');
my $token :shared = 0;
-threads->create(sub {
+my $thread = threads->create(sub {
$st->down_force(2);
is($token++, 0, 'Thread got semaphore');
$sm->up();
@@ -38,7 +38,7 @@ threads->create(sub {
$st->down();
is($token++, 3, 'Thread done');
$sm->up();
-})->detach();
+});
$sm->down();
is($token++, 1, 'Main has semaphore');
@@ -54,6 +54,8 @@ is($token, 4, 'Main re-got semaphore');
ok(1, 'Main done');
threads::yield();
+$thread->join;
+
exit(0);
# EOF