X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F59-yield-threads.t;fp=t%2F59-yield-threads.t;h=fbe054f73aa8d4b36ecbacfc5d004e3bd80ddcfa;hb=1cac52223ba0983d5d4007ab608fe4ea645eb037;hp=0000000000000000000000000000000000000000;hpb=ca50ad37afae0c65ddc432c03f68d5cefae4de29;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/59-yield-threads.t b/t/59-yield-threads.t new file mode 100644 index 0000000..fbe054f --- /dev/null +++ b/t/59-yield-threads.t @@ -0,0 +1,46 @@ +#!perl -T + +use strict; +use warnings; + +use lib 't/lib'; +use Scope::Upper::TestThreads; + +use Test::Leaner; + +use Scope::Upper qw; + +our $z; + +sub up1 { + my $tid = threads->tid(); + local $z = $tid; + my $p = "[$tid] up1"; + + usleep rand(1e6); + + my @res = ( + -1, + do { + my @dummy = ( + 999, + map { + my $foo = yield $tid .. $tid + 2 => UP; + fail "$p: not reached"; + } 666 + ); + fail "$p: not reached"; + }, + -2 + ); + + is_deeply \@res, [ -1, $tid .. $tid + 2, -2 ], "$p: yielded correctly"; +} + +my @threads = map spawn(\&up1), 1 .. 30; + +$_->join for @threads; + +pass 'done'; + +done_testing(scalar(@threads) + 1);