Bizarre fork failure
[dbsrgits/DBIx-Class.git] / t / storage / factory_fork.t
CommitLineData
2ff179e2 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6
7use lib qw(t/lib);
8use DBICTest;
9
10for my $type (qw/PG MYSQL/) {
11
12 SKIP: {
13 skip "Skipping $type tests without DBICTEST_${type}_DSN", 1
14 unless $ENV{"DBICTEST_${type}_DSN"};
15
16 my $schema = DBICTest::Schema->connect (@ENV{map { "DBICTEST_${type}_${_}" } qw/DSN USER PASS/});
17
18 # emulate a singleton-factory, just cache the object *somewhere in a different package*
19 # without this everything works
20 $DBICTest::FakeSchemaFactory::schema = $schema;
21
22 # so we can see the retry exceptions (if any)
23 $ENV{DBIC_DBIRETRY_DEBUG} = 1;
24
25 ok (!$schema->storage->connected, "$type: start disconnected");
26
27 lives_ok (sub {
28 $schema->txn_do (sub {
29
30 ok ($schema->storage->connected, "$type: transaction starts connected");
31
32 my $pid = fork();
33 SKIP: {
34 skip "Fork failed: $!", 1 if (! defined $pid);
35
36 if ($pid) {
37 sleep 1;
38 }
39 else {
40 exit 0;
41 }
42
43 ok ($schema->storage->connected, "$type: parent still connected (in txn_do)");
44 }
45 });
46 });
47
48 ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)");
49
50 undef $DBICTest::FakeSchemaFactory::schema;
51 }
52}
53
54done_testing;