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