]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/80-threads.t
Generate binop comparators on the fly
[perl/modules/Test-Leaner.git] / t / 80-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 sub skipall {
7  my ($msg) = @_;
8  require Test::Leaner;
9  Test::Leaner::plan(skip_all => $msg);
10 }
11
12 use Config qw/%Config/;
13
14 BEGIN {
15  my $force = $ENV{PERL_TEST_LEANER_TEST_THREADS} ? 1 : !1;
16  my $t_v   = $force ? '0' : '1.67';
17  skipall 'This perl wasn\'t built to support threads'
18                                                     unless $Config{useithreads};
19  skipall 'perl 5.13.4 required to test thread safety'
20                                                 unless $force or $] >= 5.013004;
21  skipall "threads $t_v required to test thread safety"
22                                               unless eval "use threads $t_v; 1";
23 }
24
25 use Test::Leaner; # after threads
26
27 BEGIN {
28  skipall 'This Test::Leaner isn\'t thread safe' unless Test::Leaner::THREADSAFE;
29  plan tests => 8 * 10;
30  defined and diag "Using threads $_" for $threads::VERSION;
31 }
32
33 sub tick {
34  sleep 1 if rand() < 0.5;
35 }
36
37 sub worker {
38  my $tid = threads->tid;
39  diag "spawned thread $tid";
40  tick;
41  for (1 .. 10) {
42   cmp_ok 1, '==', '1.0', "test $_ in thread $tid";
43   tick;
44  }
45 }
46
47 $_->join for map threads->create(\&worker), 1 .. 8;