X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F80-threads.t;fp=t%2F80-threads.t;h=3b0a5959b5e06229ae5b667056e4f6b89112daf0;hb=eb0bd56068ca67ea93f621ef38f59dec9bdbbcd8;hp=0000000000000000000000000000000000000000;hpb=41367a04c268486fb815420a103f80e28ffefd63;p=perl%2Fmodules%2FTest-Leaner.git diff --git a/t/80-threads.t b/t/80-threads.t new file mode 100644 index 0000000..3b0a595 --- /dev/null +++ b/t/80-threads.t @@ -0,0 +1,47 @@ +#!perl -T + +use strict; +use warnings; + +sub skipall { + my ($msg) = @_; + require Test::Leaner; + Test::Leaner::plan(skip_all => $msg); +} + +use Config qw/%Config/; + +BEGIN { + my $force = $ENV{PERL_TEST_LEANER_TEST_THREADS} ? 1 : !1; + my $t_v = $force ? '0' : '1.67'; + skipall 'This perl wasn\'t built to support threads' + unless $Config{useithreads}; + skipall 'perl 5.13.4 required to test thread safety' + unless $force or $] >= 5.013004; + skipall "threads $t_v required to test thread safety" + unless eval "use threads $t_v; 1"; +} + +use Test::Leaner; # after threads + +BEGIN { + skipall 'This Test::Leaner isn\'t thread safe' unless Test::Leaner::THREADSAFE; + plan tests => 8 * 10; + defined and diag "Using threads $_" for $threads::VERSION; +} + +sub tick { + sleep 1 if rand() < 0.5; +} + +sub worker { + my $tid = threads->tid; + diag "spawned thread $tid"; + tick; + for (1 .. 10) { + pass "test $_ in thread $tid"; + tick; + } +} + +$_->join for map threads->create(\&worker), 1 .. 8;