line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
9768
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dancer2::Plugin::Queue::Role::Test; |
6
|
|
|
|
|
|
|
# ABSTRACT: A Test::Roo::Role for testing Queue backends |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
768
|
use Test::Roo::Role; |
|
1
|
|
|
|
|
489
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
976
|
use MooX::Types::MooseLike::Base qw/Str HashRef CodeRef/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
21221
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
57535
|
|
|
1
|
|
|
|
|
39
|
|
14
|
1
|
|
|
1
|
|
804
|
use Test::TCP; |
|
1
|
|
|
|
|
41109
|
|
|
1
|
|
|
|
|
175
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#pod =attr backend |
17
|
|
|
|
|
|
|
#pod |
18
|
|
|
|
|
|
|
#pod The short name for a Dancer2::Plugin::Queue implementation to test. |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod =cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has backend => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => Str, |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#pod =attr options |
29
|
|
|
|
|
|
|
#pod |
30
|
|
|
|
|
|
|
#pod A hash reference of options to configure the backend. |
31
|
|
|
|
|
|
|
#pod |
32
|
|
|
|
|
|
|
#pod =cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has options => ( |
35
|
|
|
|
|
|
|
is => 'lazy', |
36
|
|
|
|
|
|
|
isa => HashRef, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
0
|
|
|
sub _build_options { } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has _server => ( |
42
|
|
|
|
|
|
|
is => 'lazy', |
43
|
|
|
|
|
|
|
isa => CodeRef, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _build__server { |
47
|
1
|
|
|
1
|
|
572
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
return sub { |
49
|
|
|
|
|
|
|
package |
50
|
|
|
|
|
|
|
MyServer; |
51
|
1
|
|
|
1
|
|
833
|
use Dancer2 ':syntax'; |
|
1
|
|
|
|
|
325020
|
|
|
1
|
|
|
|
|
7
|
|
52
|
1
|
|
|
1
|
|
89696
|
use Dancer2::Plugin::Queue; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
53
|
0
|
|
|
0
|
|
|
my $port = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
set confdir => '.'; |
56
|
0
|
|
|
|
|
|
set startup_info => 0; |
57
|
0
|
|
|
|
|
|
set show_errors => 1; |
58
|
0
|
|
|
|
|
|
set plugins => { |
59
|
|
|
|
|
|
|
Queue => { |
60
|
|
|
|
|
|
|
default => { |
61
|
|
|
|
|
|
|
class => $self->backend, |
62
|
|
|
|
|
|
|
options => $self->options, |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
get '/add' => sub { |
68
|
0
|
|
|
|
|
|
queue->add_msg( params->{msg} ); |
69
|
0
|
|
|
|
|
|
my ( $msg, $body ) = queue->get_msg; |
70
|
0
|
|
|
|
|
|
queue->remove_msg($msg); |
71
|
0
|
|
|
|
|
|
return $body; |
72
|
0
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
Dancer2->runner->server->{ port } = $port; |
75
|
0
|
|
|
|
|
|
start; |
76
|
1
|
|
|
|
|
25
|
}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
test 'queue and dequeue' => sub { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
test_tcp( |
82
|
|
|
|
|
|
|
client => sub { |
83
|
|
|
|
|
|
|
my $port = shift; |
84
|
|
|
|
|
|
|
my $url = "http://localhost:$port/"; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $ua = HTTP::Tiny->new; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $res = $ua->get( $url . "add?msg=Hello%20World" ); |
89
|
|
|
|
|
|
|
like $res->{content}, qr/Hello World/i, "sent and receieved message"; |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
server => $self->_server, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4 et: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |