Commit | Line | Data |
2ff179e2 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
10 | for 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* |
527b5739 |
19 | # to induce out-of-order destruction |
2ff179e2 |
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) { |
fa394969 |
37 | note "Parent $$ sleeping..."; |
38 | wait(); |
39 | note "Parent $$ woken up after child $pid exit"; |
2ff179e2 |
40 | } |
41 | else { |
fa394969 |
42 | note "Child $$ terminating"; |
2ff179e2 |
43 | exit 0; |
44 | } |
45 | |
46 | ok ($schema->storage->connected, "$type: parent still connected (in txn_do)"); |
47 | } |
48 | }); |
49 | }); |
50 | |
51 | ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)"); |
52 | |
53 | undef $DBICTest::FakeSchemaFactory::schema; |
54 | } |
55 | } |
56 | |
57 | done_testing; |