File: 54-unwind-threads.t

package info (click to toggle)
libscope-upper-perl 0.34-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 632 kB
  • sloc: perl: 7,578; ansic: 653; makefile: 8
file content (54 lines) | stat: -rw-r--r-- 775 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!perl

use strict;
use warnings;

use lib 't/lib';
use VPIT::TestHelpers (
 threads => [ 'Scope::Upper' => 'Scope::Upper::SU_THREADSAFE()' ],
 'usleep',
);

use Test::Leaner;

use Scope::Upper qw<unwind UP>;

our $z;

sub up1 {
 my $tid  = threads->tid();
 local $z = $tid;
 my $p    = "[$tid] up1";

 usleep rand(2.5e5);

 my @res = (
  -1,
  sub {
   my @dummy = (
    999,
    sub {
     my $foo = unwind $tid .. $tid + 2 => UP;
     fail "$p: not reached";
    }->()
   );
   fail "$p: not reached";
  }->(),
  -2
 );

 is_deeply \@res, [ -1, $tid .. $tid + 2, -2 ], "$p: unwinded correctly";

 return 1;
}

my @threads = map spawn(\&up1), 1 .. 30;

my $completed = 0;
for my $thr (@threads) {
 ++$completed if $thr->join;
}

pass 'done';

done_testing($completed + 1);