1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
5 unless ($Config{useithreads}) {
6 print "1..0 # SKIP your perl does not support ithreads\n";
10 if ($INC{'Devel/Cover.pm'}) {
11 print "1..0 # SKIP Devel::Cover does not work with threads yet\n";
21 use DBIx::Class::_Util 'sigwarn_silencer';
22 use Time::HiRes qw(time sleep);
26 plan skip_all => 'DBIC does not actively support threads before perl 5.8.5'
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;
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) {
39 my $schema = DBICTest->init_schema(no_deploy => 1);
40 isa_ok ($schema, 'DBICTest::Schema');
42 # sleep until this spot so everything starts simultaneously
43 # add "until turn of second" for prettier display
44 my $t = int( time() ) + 4;
49 local $SIG{__WARN__} = sigwarn_silencer( qr/Thread creation failed/i );
51 for (1.. $num_children) {
52 push @threads, threads->create(sub {
53 my $tid = threads->tid;
56 note ("Thread $tid starting work at " . time() );
58 my $rsrc = $schema->source('Artist');
60 isa_ok ($rsrc->schema, 'DBICTest::Schema');
61 my $s2 = $rsrc->schema->clone;
63 sleep (0.2); # without this many tasty crashes even on latest perls
65 skip "EAGAIN encountered, your system is likely bogged down: skipping rest of test", 1
66 if $! == Errno::EAGAIN();
68 die "Unable to start thread: $!";
73 ok(1, "past spawning");
75 $_->join for @threads;
76 ok(1, "past joining");
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