Bizarre fork failure
Peter Rabbitson [Mon, 26 Apr 2010 13:27:38 +0000 (13:27 +0000)]
Makefile.PL
t/storage/factory_fork.t [new file with mode: 0644]

index d29d57b..3203baf 100644 (file)
@@ -18,7 +18,6 @@ $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
 ### All of them should go to DBIx::Class::Optional::Dependencies
 ###
 
-
 name     'DBIx-Class';
 perl_version '5.008001';
 all_from 'lib/DBIx/Class.pm';
diff --git a/t/storage/factory_fork.t b/t/storage/factory_fork.t
new file mode 100644 (file)
index 0000000..30e1c6f
--- /dev/null
@@ -0,0 +1,54 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use lib qw(t/lib);
+use DBICTest;
+
+for my $type (qw/PG MYSQL/) {
+
+  SKIP: {
+    skip "Skipping $type tests without DBICTEST_${type}_DSN", 1
+      unless $ENV{"DBICTEST_${type}_DSN"};
+
+    my $schema = DBICTest::Schema->connect (@ENV{map { "DBICTEST_${type}_${_}" } qw/DSN USER PASS/});
+
+    # emulate a singleton-factory, just cache the object *somewhere in a different package*
+    # without this everything works
+    $DBICTest::FakeSchemaFactory::schema = $schema;
+
+    # so we can see the retry exceptions (if any)
+    $ENV{DBIC_DBIRETRY_DEBUG} = 1;
+
+    ok (!$schema->storage->connected, "$type: start disconnected");
+
+    lives_ok (sub {
+      $schema->txn_do (sub {
+
+        ok ($schema->storage->connected, "$type: transaction starts connected");
+
+        my $pid = fork();
+        SKIP: {
+          skip "Fork failed: $!", 1 if (! defined $pid);
+
+          if ($pid) {
+            sleep 1;
+          }
+          else {
+            exit 0;
+          }
+
+          ok ($schema->storage->connected, "$type: parent still connected (in txn_do)");
+        }
+      });
+    });
+
+    ok ($schema->storage->connected, "$type: parent still connected (outside of txn_do)");
+
+    undef $DBICTest::FakeSchemaFactory::schema;
+  }
+}
+
+done_testing;