]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/59-yield-threads.t
4d6d0b244b2842cc08bc915ff84b93ca0c3345ad
[perl/modules/Scope-Upper.git] / t / 59-yield-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Scope::Upper qw<yield UP>;
7
8 use lib 't/lib';
9 use VPIT::TestHelpers (
10  threads => [ 'Scope::Upper' => Scope::Upper::SU_THREADSAFE ],
11  'usleep',
12 );
13
14 use Test::Leaner;
15
16 our $z;
17
18 sub up1 {
19  my $tid  = threads->tid();
20  local $z = $tid;
21  my $p    = "[$tid] up1";
22
23  usleep rand(1e6);
24
25  my @res = (
26   -1,
27   do {
28    my @dummy = (
29     999,
30     map {
31      my $foo = yield $tid .. $tid + 2 => UP;
32      fail "$p: not reached";
33     } 666
34    );
35    fail "$p: not reached";
36   },
37   -2
38  );
39
40  is_deeply \@res, [ -1, $tid .. $tid + 2, -2 ], "$p: yielded correctly";
41 }
42
43 my @threads = map spawn(\&up1), 1 .. 30;
44
45 $_->join for @threads;
46
47 pass 'done';
48
49 done_testing(scalar(@threads) + 1);