Add some feedback to the test; shorten spinup delay.
[catagits/Catalyst-Engine-STOMP.git] / t / Catalyst-Engine-Stomp.t
CommitLineData
5c4a7793 1use Test::More;
0a663589 2
3# Tests which expect a STOMP server like ActiveMQ to exist on
4# localhost:61613, which is what you get if you just get the ActiveMQ
5# distro and run its out-of-the-box config.
6
7use Net::Stomp;
8use YAML::XS qw/ Dump Load /;
9use Data::Dumper;
10
5c4a7793 11my $stomp;
12eval {
13 $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
14};
15if ($@) {
16 plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
17 exit;
18}
19else {
20 plan tests => 12;
21}
22
0a663589 23# First fire off the server
5c4a7793 24$SIG{CHLD} = 'IGNORE';
ff3b0412 25unless (fork()) {
a6b86b35 26 system("CATALYST_DEBUG=0 $^X -Ilib -Itestapp/lib testapp/script/testapp_stomp.pl --oneshot");
ff3b0412 27 exit 0;
28}
a6b86b35 29print STDERR "server started, waiting for spinup...";
30sleep 10;
0a663589 31
32# Now be a client to that server
a6b86b35 33print STDERR "testing\n";
0a663589 34ok($stomp, 'Net::Stomp object');
35
36my $frame = $stomp->connect();
37ok($frame, 'connect to MQ server ok');
38
39my $reply_to = sprintf '%s:1', $frame->headers->{session};
40ok($frame->headers->{session}, 'got a session');
41ok(length $reply_to > 2, 'valid-looking reply_to queue');
42
43ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue');
44
45my $message = {
46 payload => { foo => 1, bar => 2 },
47 reply_to => $reply_to,
48 type => 'testaction',
49 };
50my $text = Dump($message);
51ok($text, 'compose message');
52
53$stomp->send( { destination => '/queue/testcontroller', body => $text } );
54
55my $reply_frame = $stomp->receive_frame();
56ok($reply_frame, 'got a reply');
57ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue');
58ok($reply_frame->body, 'has a body');
59
60my $response = Load($reply_frame->body);
61ok($response, 'YAML response ok');
62ok($response->{type} eq 'testaction_response', 'correct type');
63
64ok($stomp->disconnect, 'disconnected');
65