Make tests use strict and warnings. Cleanup the killing of activemq so that it happen...
[catagits/Catalyst-Engine-STOMP.git] / t / lib / TestServer.pm
CommitLineData
8edb2b46 1package StompRole;
2use Moose::Role;
3use namespace::autoclean;
4
5after 'disconnect' => sub {
6 delete shift->{___activemq};
7};
8
9package TestServer;
10use strict;
11use warnings;
12use Alien::ActiveMQ;
13use Test::More;
14use Exporter qw/import/;
15
16our $ACTIVEMQ_VERSION = '5.2.0';
17
18our @EXPORT = qw/ start_server /;
19
20sub start_server {
21 my ($mq, $stomp);
22 eval {
23 $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
24 };
25 if ($@) {
26
27 unless (Alien::ActiveMQ->is_version_installed($ACTIVEMQ_VERSION)) {
28 plan 'skip_all' => 'No ActiveMQ server installed by Alien::ActiveMQ, try running the "install-activemq" command';
29 exit;
30 }
31
32 $mq = Alien::ActiveMQ->run_server($ACTIVEMQ_VERSION);
33
34 eval {
35 $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
36 };
37 if ($@) {
38 plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
39 exit;
40 }
41 }
42
43 $SIG{CHLD} = 'IGNORE';
44 unless (fork()) {
45 system("$^X -Ilib -Itestapp/lib testapp/script/stomptestapp_stomp.pl --oneshot");
46 exit 0;
47 }
48 print STDERR "server started, waiting for spinup...";
49 sleep 20;
50
51 $stomp->{___activemq} = $mq if $mq;
52 StompRole->meta->apply($stomp);
53 return $stomp;
54}
55