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