Commit | Line | Data |
2ff179e2 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | |
199fbc45 |
7 | use DBIx::Class::Optional::Dependencies (); |
8 | |
2ff179e2 |
9 | use lib qw(t/lib); |
10 | use DBICTest; |
11 | |
475713af |
12 | plan skip_all => 'Test segfaults on Win32' if $^O eq 'MSWin32'; |
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 | |
5e51f715 |
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 | |
41 | # so we can see the retry exceptions (if any) |
42 | $ENV{DBIC_DBIRETRY_DEBUG} = 1; |
43 | |
44 | ok (!$schema->storage->connected, "$type: start disconnected"); |
45 | |
46 | lives_ok (sub { |
47 | $schema->txn_do (sub { |
48 | |
49 | ok ($schema->storage->connected, "$type: transaction starts connected"); |
50 | |
51 | my $pid = fork(); |
52 | SKIP: { |
53 | skip "Fork failed: $!", 1 if (! defined $pid); |
54 | |
55 | if ($pid) { |
fa394969 |
56 | note "Parent $$ sleeping..."; |
57 | wait(); |
58 | note "Parent $$ woken up after child $pid exit"; |
2ff179e2 |
59 | } |
60 | else { |
fa394969 |
61 | note "Child $$ terminating"; |
66441708 |
62 | undef $DBICTest::FakeSchemaFactory::schema; |
2ff179e2 |
63 | exit 0; |
64 | } |
65 | |
66 | ok ($schema->storage->connected, "$type: parent still connected (in txn_do)"); |
67 | } |
68 | }); |
69 | }); |
70 | |
71 | ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)"); |
72 | |
73 | undef $DBICTest::FakeSchemaFactory::schema; |
74 | } |
75 | } |
76 | |
77 | done_testing; |