Fix starting test server
[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/;
3a0d5cfc 15use FindBin;
8edb2b46 16
17our $ACTIVEMQ_VERSION = '5.2.0';
18
19our @EXPORT = qw/ start_server /;
20
21sub start_server {
22 my ($mq, $stomp);
23 eval {
24 $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
25 };
26 if ($@) {
27
28 unless (Alien::ActiveMQ->is_version_installed($ACTIVEMQ_VERSION)) {
29 plan 'skip_all' => 'No ActiveMQ server installed by Alien::ActiveMQ, try running the "install-activemq" command';
30 exit;
31 }
32
33 $mq = Alien::ActiveMQ->run_server($ACTIVEMQ_VERSION);
34
35 eval {
36 $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
37 };
38 if ($@) {
39 plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
40 exit;
41 }
42 }
43
44 $SIG{CHLD} = 'IGNORE';
45 unless (fork()) {
3a0d5cfc 46 system("$^X -I$FindBin::Bin/lib $FindBin::Bin/script/stomptestapp_stomp.pl --oneshot");
8edb2b46 47 exit 0;
48 }
49 print STDERR "server started, waiting for spinup...";
50 sleep 20;
51
52 $stomp->{___activemq} = $mq if $mq;
53 StompRole->meta->apply($stomp);
54 return $stomp;
55}
56