(travis) Make sure DEVREL_DEPS + CLEANTEST-false behaves as intended
[dbsrgits/DBIx-Class.git] / t / 51threadnodb.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use Config;
4 BEGIN {
5   unless ($Config{useithreads}) {
6     print "1..0 # SKIP your perl does not support ithreads\n";
7     exit 0;
8   }
9
10   if ($INC{'Devel/Cover.pm'}) {
11     print "1..0 # SKIP Devel::Cover does not work with threads yet\n";
12     exit 0;
13   }
14 }
15 use threads;
16
17 use strict;
18 use warnings;
19 use Test::More;
20 use Errno ();
21 use DBIx::Class::_Util 'sigwarn_silencer';
22 use Time::HiRes qw(time sleep);
23
24 use DBICTest;
25
26 plan skip_all => 'DBIC does not actively support threads before perl 5.8.5'
27   if "$]" < 5.008005;
28
29 plan skip_all => 'Potential problems on Win32 Perl < 5.14 and Variable::Magic - investigation pending'
30   if $^O eq 'MSWin32' && "$]" < 5.014 && DBICTest::RunMode->is_plain;
31
32 # README: If you set the env var to a number greater than 5,
33 #   we will use that many children
34 my $num_children = $ENV{DBICTEST_THREAD_STRESS} || 1;
35 if($num_children !~ /^[0-9]+$/ || $num_children < 5) {
36    $num_children = 5;
37 }
38
39 my $schema = DBICTest->init_schema(no_deploy => 1);
40 isa_ok ($schema, 'DBICTest::Schema');
41
42 # sleep until this spot so everything starts simultaneously
43 # add "until turn of second" for prettier display
44 my $t = int( time() ) + 4;
45
46 my @threads;
47 SKIP: {
48
49   local $SIG{__WARN__} = sigwarn_silencer( qr/Thread creation failed/i );
50
51   for (1.. $num_children) {
52     push @threads, threads->create(sub {
53       my $tid = threads->tid;
54
55       sleep ($t - time);
56       note ("Thread $tid starting work at " . time() );
57
58       my $rsrc = $schema->source('Artist');
59       undef $schema;
60       isa_ok ($rsrc->schema, 'DBICTest::Schema');
61       my $s2 = $rsrc->schema->clone;
62
63       sleep (0.2); # without this many tasty crashes even on latest perls
64     }) || do {
65       skip "EAGAIN encountered, your system is likely bogged down: skipping rest of test", 1
66         if $! == Errno::EAGAIN();
67
68       die "Unable to start thread: $!";
69     };
70   }
71 }
72
73 ok(1, "past spawning");
74
75 $_->join for @threads;
76 ok(1, "past joining");
77
78 # Too many threading bugs on exit, none of which have anything to do with
79 # the actual stuff we test
80 $ENV{DBICTEST_DIRTY_EXIT} = 1
81   if "$]"< 5.012;
82
83 done_testing;