]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/54-unwind-threads.t
Harden t/54-unwind-threads.t against stray exits
[perl/modules/Scope-Upper.git] / t / 54-unwind-threads.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7 use VPIT::TestHelpers (
8  threads => [ 'Scope::Upper' => 'Scope::Upper::SU_THREADSAFE()' ],
9  'usleep',
10 );
11
12 use Test::Leaner;
13
14 use Scope::Upper qw<unwind UP>;
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(2.5e5);
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  return 1;
43 }
44
45 my @threads = map spawn(\&up1), 1 .. 30;
46
47 my $completed = 0;
48 for my $thr (@threads) {
49  ++$completed if $thr->join;
50 }
51
52 pass 'done';
53
54 done_testing($completed + 1);