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 | |
9dfb034f |
12 | plan skip_all => 'Test segfaults on Win32 - investigation pending' |
13 | if $^O eq 'MSWin32' && DBICTest::RunMode->is_plain; |
475713af |
14 | |
5e51f715 |
15 | for my $type (qw/PG MYSQL SQLite/) { |
2ff179e2 |
16 | |
17 | SKIP: { |
5e51f715 |
18 | my @dsn = $type eq 'SQLite' |
19 | ? DBICTest->_database(sqlite_use_file => 1) |
20 | : do { |
21 | skip "Skipping $type tests without DBICTEST_${type}_DSN", 1 |
22 | unless $ENV{"DBICTEST_${type}_DSN"}; |
23 | @ENV{map { "DBICTEST_${type}_${_}" } qw/DSN USER PASS/} |
24 | } |
25 | ; |
2ff179e2 |
26 | |
199fbc45 |
27 | if ($type eq 'PG') { |
28 | skip "skipping Pg tests without dependencies installed", 1 |
29 | unless DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_pg'); |
30 | } |
31 | elsif ($type eq 'MYSQL') { |
32 | skip "skipping MySQL tests without dependencies installed", 1 |
33 | unless DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mysql'); |
34 | } |
35 | |
5e51f715 |
36 | my $schema = DBICTest::Schema->connect (@dsn); |
2ff179e2 |
37 | |
38 | # emulate a singleton-factory, just cache the object *somewhere in a different package* |
527b5739 |
39 | # to induce out-of-order destruction |
2ff179e2 |
40 | $DBICTest::FakeSchemaFactory::schema = $schema; |
41 | |
42 | # so we can see the retry exceptions (if any) |
43 | $ENV{DBIC_DBIRETRY_DEBUG} = 1; |
44 | |
45 | ok (!$schema->storage->connected, "$type: start disconnected"); |
46 | |
47 | lives_ok (sub { |
48 | $schema->txn_do (sub { |
49 | |
50 | ok ($schema->storage->connected, "$type: transaction starts connected"); |
51 | |
52 | my $pid = fork(); |
53 | SKIP: { |
54 | skip "Fork failed: $!", 1 if (! defined $pid); |
55 | |
56 | if ($pid) { |
fa394969 |
57 | note "Parent $$ sleeping..."; |
58 | wait(); |
59 | note "Parent $$ woken up after child $pid exit"; |
2ff179e2 |
60 | } |
61 | else { |
fa394969 |
62 | note "Child $$ terminating"; |
66441708 |
63 | undef $DBICTest::FakeSchemaFactory::schema; |
2ff179e2 |
64 | exit 0; |
65 | } |
66 | |
67 | ok ($schema->storage->connected, "$type: parent still connected (in txn_do)"); |
68 | } |
69 | }); |
70 | }); |
71 | |
72 | ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)"); |
73 | |
74 | undef $DBICTest::FakeSchemaFactory::schema; |
75 | } |
76 | } |
77 | |
78 | done_testing; |