Some cosmetic fixes in ANFANG
[dbsrgits/DBIx-Class.git] / t / storage / global_destruction.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
2ff179e2 3use strict;
4use warnings;
5
6use Test::More;
2ff179e2 7
db83437e 8# so we can see the retry exceptions (if any)
9BEGIN { $ENV{DBIC_STORAGE_RETRY_DEBUG} = 1 }
10
199fbc45 11use DBIx::Class::Optional::Dependencies ();
12
c0329273 13
2ff179e2 14use DBICTest;
15
5e51f715 16for my $type (qw/PG MYSQL SQLite/) {
2ff179e2 17
18 SKIP: {
3cff955a 19
20 DBIx::Class::Optional::Dependencies->skip_without( 'test_rdbms_' . lc $type );
21
5e51f715 22 my @dsn = $type eq 'SQLite'
3cff955a 23 ? ( DBICTest->_database(sqlite_use_file => 1) )
24 : ( @ENV{map { "DBICTEST_${type}_${_}" } qw/DSN USER PASS/} )
5e51f715 25 ;
2ff179e2 26
c7e85630 27 my $schema = DBICTest::Schema->connect (@dsn);
2ff179e2 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
2ff179e2 33 ok (!$schema->storage->connected, "$type: start disconnected");
34
ee204dc3 35 $schema->txn_do (sub {
2ff179e2 36
ee204dc3 37 ok ($schema->storage->connected, "$type: transaction starts connected");
2ff179e2 38
ee204dc3 39 my $pid = fork();
40 SKIP: {
41 skip "Fork failed: $!", 1 if (! defined $pid);
2ff179e2 42
ee204dc3 43 if ($pid) {
44 note "Parent $$ sleeping...";
45 wait();
46 note "Parent $$ woken up after child $pid exit";
47 }
48 else {
49 note "Child $$ terminating";
50 undef $DBICTest::FakeSchemaFactory::schema;
51 exit 0;
2ff179e2 52 }
ee204dc3 53
54 ok ($schema->storage->connected, "$type: parent still connected (in txn_do)");
55 }
2ff179e2 56 });
57
58 ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)");
59
60 undef $DBICTest::FakeSchemaFactory::schema;
61 }
62}
63
64done_testing;