Make tests use strict and warnings. Cleanup the killing of activemq so that it happen...
[catagits/Catalyst-Engine-STOMP.git] / t / lib / TestServer.pm
diff --git a/t/lib/TestServer.pm b/t/lib/TestServer.pm
new file mode 100644 (file)
index 0000000..2ce73a2
--- /dev/null
@@ -0,0 +1,55 @@
+package StompRole;
+use Moose::Role;
+use namespace::autoclean;
+
+after 'disconnect' => sub {
+    delete shift->{___activemq};
+};
+
+package TestServer;
+use strict;
+use warnings;
+use Alien::ActiveMQ;
+use Test::More;
+use Exporter qw/import/;
+
+our $ACTIVEMQ_VERSION = '5.2.0';
+
+our @EXPORT = qw/ start_server /;
+
+sub start_server {
+    my ($mq, $stomp);
+    eval {
+        $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
+    };
+    if ($@) {
+
+        unless (Alien::ActiveMQ->is_version_installed($ACTIVEMQ_VERSION)) {
+            plan 'skip_all' => 'No ActiveMQ server installed by Alien::ActiveMQ, try running the "install-activemq" command';
+            exit;
+        }
+
+        $mq = Alien::ActiveMQ->run_server($ACTIVEMQ_VERSION);
+
+        eval {
+            $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
+        };
+        if ($@) {
+            plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
+            exit;
+        }
+    }
+
+    $SIG{CHLD} = 'IGNORE';
+    unless (fork()) {
+           system("$^X -Ilib -Itestapp/lib testapp/script/stomptestapp_stomp.pl --oneshot");
+           exit 0;
+    }
+    print STDERR "server started, waiting for spinup...";
+    sleep 20;
+
+    $stomp->{___activemq} = $mq if $mq;
+    StompRole->meta->apply($stomp);
+    return $stomp;
+}
+