]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/54-unwind-threads.t
559993823e2759160260b652b14f77bd36038f88
[perl/modules/Scope-Upper.git] / t / 54-unwind-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Scope::Upper qw<unwind 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   sub {
28    my @dummy = (
29     999,
30     sub {
31      my $foo = unwind $tid .. $tid + 2 => UP;
32      fail "$p: not reached";
33     }->()
34    );
35    fail "$p: not reached";
36   }->(),
37   -2
38  );
39
40  is_deeply \@res, [ -1, $tid .. $tid + 2, -2 ], "$p: unwinded 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);