fix and regression test for RT #62642
[dbsrgits/DBIx-Class.git] / t / storage / global_destruction.t
CommitLineData
2ff179e2 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6
7use lib qw(t/lib);
8use DBICTest;
9
10for 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
57done_testing;