Make sure tests still pass in a fork-limited environment
[dbsrgits/DBIx-Class.git] / t / 51threadnodb.t
CommitLineData
a4367b26 1use Config;
2BEGIN {
3 unless ($Config{useithreads}) {
4 print "1..0 # SKIP your perl does not support ithreads\n";
5 exit 0;
6 }
f15baf68 7
8 if ($INC{'Devel/Cover.pm'}) {
9 print "1..0 # SKIP Devel::Cover does not work with threads yet\n";
10 exit 0;
11 }
a4367b26 12}
13use threads;
14
15use strict;
16use warnings;
17use Test::More;
fac17a39 18use DBIx::Class::_Util 'sigwarn_silencer';
a4367b26 19
9dfb034f 20use lib qw(t/lib);
21use DBICTest;
22
a4367b26 23plan skip_all => 'DBIC does not actively support threads before perl 5.8.5'
24 if $] < '5.008005';
25
9dfb034f 26plan skip_all => 'Potential problems on Win32 Perl < 5.14 and Variable::Magic - investigation pending'
27 if $^O eq 'MSWin32' && $] < 5.014 && DBICTest::RunMode->is_plain;
a4367b26 28
29# README: If you set the env var to a number greater than 10,
30# we will use that many children
31my $num_children = $ENV{DBICTEST_THREAD_STRESS} || 1;
32if($num_children !~ /^[0-9]+$/ || $num_children < 10) {
33 $num_children = 10;
34}
35
36my $schema = DBICTest->init_schema(no_deploy => 1);
37isa_ok ($schema, 'DBICTest::Schema');
38
39my @threads;
fac17a39 40SKIP: {
41
42 local $SIG{__WARN__} = sigwarn_silencer( qr/Thread creation failed/i );
43
44 for (1.. $num_children) {
45 push @threads, threads->create(sub {
46 my $rsrc = $schema->source('Artist');
47 undef $schema;
48 isa_ok ($rsrc->schema, 'DBICTest::Schema');
49 my $s2 = $rsrc->schema->clone;
50
51 sleep 1; # without this many tasty crashes
52 }) || do {
53 skip "EAGAIN encountered, your system is likely bogged down: skipping rest of test", 1
54 if $! == Errno::EAGAIN();
55
56 die "Unable to start thread: $!";
57 };
58 }
59}
60
a4367b26 61ok(1, "past spawning");
62
63$_->join for @threads;
64ok(1, "past joining");
65
66done_testing;