From: Vincent Pit Date: Tue, 24 Mar 2015 00:14:16 +0000 (-0300) Subject: In t/09-load-threads.t, handle spawn() failures gracefully X-Git-Tag: v0.27~11 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=7f24c0f5e913f78df408f9c70f6559d42a116c90;p=perl%2Fmodules%2FScope-Upper.git In t/09-load-threads.t, handle spawn() failures gracefully --- diff --git a/t/09-load-threads.t b/t/09-load-threads.t index b63a51e..3bd92f9 100644 --- a/t/09-load-threads.t +++ b/t/09-load-threads.t @@ -55,6 +55,8 @@ BEGIN { ) } +my $could_not_create_thread = 'Could not create thread'; + use Test::Leaner tests => 1 + (2 + 2 * 2) + 6 + (1 + 2 * 4); sub is_loaded { @@ -80,72 +82,88 @@ is_loaded 0, 'main body, beginning'; # Test serial loadings -my $thr = spawn(sub { - my $here = "first serial thread"; - is_loaded 0, "$here, beginning"; +SKIP: { + my $thr = spawn(sub { + my $here = "first serial thread"; + is_loaded 0, "$here, beginning"; - do_load; - is_loaded 1, "$here, after loading"; + do_load; + is_loaded 1, "$here, after loading"; - return; -}); + return; + }); -$thr->join; -if (my $err = $thr->error) { - die $err; + skip "$could_not_create_thread (serial 1)" => 2 unless defined $thr; + + $thr->join; + if (my $err = $thr->error) { + die $err; + } } is_loaded 0, 'main body, in between serial loadings'; -$thr = spawn(sub { - my $here = "second serial thread"; - is_loaded 0, "$here, beginning"; +SKIP: { + my $thr = spawn(sub { + my $here = "second serial thread"; + is_loaded 0, "$here, beginning"; + + do_load; + is_loaded 1, "$here, after loading"; - do_load; - is_loaded 1, "$here, after loading"; + return; + }); - return; -}); + skip "$could_not_create_thread (serial 2)" => 2 unless defined $thr; -$thr->join; -if (my $err = $thr->error) { - die $err; + $thr->join; + if (my $err = $thr->error) { + die $err; + } } is_loaded 0, 'main body, after serial loadings'; # Test nested loadings -$thr = spawn(sub { - my $here = 'parent thread'; - is_loaded 0, "$here, beginning"; - - my $kid = spawn(sub { - my $here = 'child thread'; +SKIP: { + my $thr = spawn(sub { + my $here = 'parent thread'; is_loaded 0, "$here, beginning"; + SKIP: { + my $kid = spawn(sub { + my $here = 'child thread'; + is_loaded 0, "$here, beginning"; + + do_load; + is_loaded 1, "$here, after loading"; + + return; + }); + + skip "$could_not_create_thread (nested child)" => 2 unless defined $kid; + + $kid->join; + if (my $err = $kid->error) { + die "in child thread: $err\n"; + } + } + + is_loaded 0, "$here, after child terminated"; + do_load; is_loaded 1, "$here, after loading"; return; }); - $kid->join; - if (my $err = $kid->error) { - die "in child thread: $err\n"; - } - - is_loaded 0, "$here, after child terminated"; + skip "$could_not_create_thread (nested parent)" => (3 + 2) unless defined $thr; - do_load; - is_loaded 1, "$here, after loading"; - - return; -}); - -$thr->join; -if (my $err = $thr->error) { - die $err; + $thr->join; + if (my $err = $thr->error) { + die $err; + } } is_loaded 0, 'main body, after nested loadings'; @@ -177,54 +195,60 @@ sub sync_slave { } } -my $thr1 = spawn(sub { - my $here = 'first simultaneous thread'; - is_loaded 0, "$here, beginning"; - sync_slave 0; +SKIP: { + my $thr1 = spawn(sub { + my $here = 'first simultaneous thread'; + is_loaded 0, "$here, beginning"; + sync_slave 0; - do_load; - is_loaded 1, "$here, after loading"; - sync_slave 1; - sync_slave 2; + do_load; + is_loaded 1, "$here, after loading"; + sync_slave 1; + sync_slave 2; - sync_slave 3; - is_loaded 1, "$here, still loaded while also loaded in the other thread"; - sync_slave 4; + sync_slave 3; + is_loaded 1, "$here, still loaded while also loaded in the other thread"; + sync_slave 4; - is_loaded 1, "$here, end"; + is_loaded 1, "$here, end"; - return; -}); + return; + }); -my $thr2 = spawn(sub { - my $here = 'second simultaneous thread'; - is_loaded 0, "$here, beginning"; - sync_slave 0; + skip "$could_not_create_thread (parallel 1)" => (4 * 2) unless defined $thr1; - sync_slave 1; - is_loaded 0, "$here, loaded in other thread but not here"; - sync_slave 2; + my $thr2 = spawn(sub { + my $here = 'second simultaneous thread'; + is_loaded 0, "$here, beginning"; + sync_slave 0; + + sync_slave 1; + is_loaded 0, "$here, loaded in other thread but not here"; + sync_slave 2; + + do_load; + is_loaded 1, "$here, after loading"; + sync_slave 3; + sync_slave 4; - do_load; - is_loaded 1, "$here, after loading"; - sync_slave 3; - sync_slave 4; + is_loaded 1, "$here, end"; - is_loaded 1, "$here, end"; + return; + }); - return; -}); + sync_master($_) for 0 .. $#locks; -sync_master($_) for 0 .. $#locks; + $thr1->join; + if (my $err = $thr1->error) { + die $err; + } -$thr1->join; -if (my $err = $thr1->error) { - die $err; -} + skip "$could_not_create_thread (parallel 2)" => (4 * 1) unless defined $thr2; -$thr2->join; -if (my $err = $thr2->error) { - die $err; + $thr2->join; + if (my $err = $thr2->error) { + die $err; + } } is_loaded 0, 'main body, after simultaneous threads';