From: Peter Rabbitson Date: Fri, 26 Sep 2014 10:05:01 +0000 (+0200) Subject: Ensure threads terminate properly X-Git-Tag: v0.10011~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=40f3dfeb3711b97a0e182ee9ac6910d9f26bb722;hp=5c87a5b19e42365de81b3ef9cf6af82a74206f0f;p=p5sagit%2FClass-Accessor-Grouped.git Ensure threads terminate properly This is a prime use for the Tumbler, but one battle at a time --- diff --git a/Changes b/Changes index df9d0a4..c980d0c 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Class::Accessor::Grouped. - Soft-depend on newer (bugfixed and *simpler*) Class::XSAccessor 1.19 + - More robust threading tests 0.10010 2013-04-24 02:58 (UTC) - Fix bug with identically-named 'simple' accessors in different diff --git a/t/accessors_pp.t b/t/accessors_pp.t index b3cb9cc..8f20812 100644 --- a/t/accessors_pp.t +++ b/t/accessors_pp.t @@ -42,26 +42,46 @@ for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t/) { my ($tfn) = catfile($Bin, $tname) =~ /(.+)/; - delete $INC{$_} for ( - qw/AccessorGroups.pm AccessorGroupsRO.pm AccessorGroupsSubclass.pm AccessorGroupsParent.pm AccessorGroupsWO.pm/, + for ( + qw|AccessorGroups.pm AccessorGroups/BeenThereDoneThat.pm AccessorGroupsRO.pm AccessorGroupsSubclass.pm AccessorGroupsParent.pm AccessorGroupsWO.pm|, File::Spec::Unix->catfile ($tfn), - ); + ) { + delete $INC{$_}; + no strict 'refs'; + if (my ($mod) = $_ =~ /(.+)\.pm$/ ) { + %{"${mod}::"} = (); + } + } local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /subroutine .+ redefined/i }; do($tfn); + + 666; }; if ($has_threads) { - threads->create(sub { - threads->create(sub { - $todo->() for (1,2) } - )->join; - $todo->() for (1,2); - })->join for (1,2) + for (1,2) { + is ( + threads->create(sub { + is ( + threads->create(sub { + $todo->(); + })->join, + 666, + 'Innner thread joined ok', + ); + 777; + })->join, + 777, + 'Outer thread joined ok', + ); + + is ($todo->(), 666, "Unthreaded run ok") for (1,2); + } } else { - $todo->() for (1, 2); + is ($todo->(), 666, "Unthreaded run ok") for (1,2); } } diff --git a/t/accessors_xs.t b/t/accessors_xs.t index b373a94..63bce81 100644 --- a/t/accessors_xs.t +++ b/t/accessors_xs.t @@ -58,18 +58,32 @@ for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t/) { local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /subroutine .+ redefined/i }; do($tfn); + + 666; }; if ($has_threads) { - threads->create(sub { - threads->create(sub { - $todo->() for (1,2) } - )->join; - $todo->() for (1,2); - })->join for (1,2) + for (1,2) { + is ( + threads->create(sub { + is ( + threads->create(sub { + $todo->(); + })->join, + 666, + 'Innner thread joined ok', + ); + 777; + })->join, + 777, + 'Outer thread joined ok', + ); + + is ($todo->(), 666, "Unthreaded run ok") for (1,2); + } } else { - $todo->() for (1, 2); + is ($todo->(), 666, "Unthreaded run ok") for (1,2); } } diff --git a/t/accessors_xs_cachedwarn.t b/t/accessors_xs_cachedwarn.t index c6a5377..c8e659b 100644 --- a/t/accessors_xs_cachedwarn.t +++ b/t/accessors_xs_cachedwarn.t @@ -45,9 +45,15 @@ share(@w) if $has_threads; is ($obj->singlefield, 2, 'Normal get'); is ($obj2->singlefield, undef, 'Normal get on unrelated object'); + + 42; }; - $has_threads ? threads->create( $todo )->join : $todo->(); + is ( + ($has_threads ? threads->create( $todo )->join : $todo->()), + 42, + "Correct result after do-er", + ) } is (@w, 3, '3 warnings total');