Commit | Line | Data |
2ff179e2 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
2ff179e2 |
5 | |
db83437e |
6 | # so we can see the retry exceptions (if any) |
7 | BEGIN { $ENV{DBIC_STORAGE_RETRY_DEBUG} = 1 } |
8 | |
199fbc45 |
9 | use DBIx::Class::Optional::Dependencies (); |
10 | |
2ff179e2 |
11 | use lib qw(t/lib); |
12 | use DBICTest; |
13 | |
5e51f715 |
14 | for my $type (qw/PG MYSQL SQLite/) { |
2ff179e2 |
15 | |
16 | SKIP: { |
5e51f715 |
17 | my @dsn = $type eq 'SQLite' |
18 | ? DBICTest->_database(sqlite_use_file => 1) |
19 | : do { |
20 | skip "Skipping $type tests without DBICTEST_${type}_DSN", 1 |
21 | unless $ENV{"DBICTEST_${type}_DSN"}; |
22 | @ENV{map { "DBICTEST_${type}_${_}" } qw/DSN USER PASS/} |
23 | } |
24 | ; |
2ff179e2 |
25 | |
199fbc45 |
26 | if ($type eq 'PG') { |
27 | skip "skipping Pg tests without dependencies installed", 1 |
28 | unless DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_pg'); |
29 | } |
30 | elsif ($type eq 'MYSQL') { |
31 | skip "skipping MySQL tests without dependencies installed", 1 |
32 | unless DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mysql'); |
33 | } |
34 | |
c7e85630 |
35 | my $schema = DBICTest::Schema->connect (@dsn); |
2ff179e2 |
36 | |
37 | # emulate a singleton-factory, just cache the object *somewhere in a different package* |
527b5739 |
38 | # to induce out-of-order destruction |
2ff179e2 |
39 | $DBICTest::FakeSchemaFactory::schema = $schema; |
40 | |
2ff179e2 |
41 | ok (!$schema->storage->connected, "$type: start disconnected"); |
42 | |
ee204dc3 |
43 | $schema->txn_do (sub { |
2ff179e2 |
44 | |
ee204dc3 |
45 | ok ($schema->storage->connected, "$type: transaction starts connected"); |
2ff179e2 |
46 | |
ee204dc3 |
47 | my $pid = fork(); |
48 | SKIP: { |
49 | skip "Fork failed: $!", 1 if (! defined $pid); |
2ff179e2 |
50 | |
ee204dc3 |
51 | if ($pid) { |
52 | note "Parent $$ sleeping..."; |
53 | wait(); |
54 | note "Parent $$ woken up after child $pid exit"; |
55 | } |
56 | else { |
57 | note "Child $$ terminating"; |
58 | undef $DBICTest::FakeSchemaFactory::schema; |
59 | exit 0; |
2ff179e2 |
60 | } |
ee204dc3 |
61 | |
62 | ok ($schema->storage->connected, "$type: parent still connected (in txn_do)"); |
63 | } |
2ff179e2 |
64 | }); |
65 | |
66 | ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)"); |
67 | |
68 | undef $DBICTest::FakeSchemaFactory::schema; |
69 | } |
70 | } |
71 | |
72 | done_testing; |