line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::MultiModule::Test; |
2
|
|
|
|
|
|
|
$App::MultiModule::Test::VERSION = '1.143160'; |
3
|
34
|
|
|
34
|
|
252438
|
use strict;use warnings; |
|
34
|
|
|
34
|
|
56
|
|
|
34
|
|
|
|
|
1076
|
|
|
34
|
|
|
|
|
136
|
|
|
34
|
|
|
|
|
42
|
|
|
34
|
|
|
|
|
1064
|
|
4
|
34
|
|
|
34
|
|
1926
|
use POSIX ":sys_wait_h"; |
|
34
|
|
|
|
|
20126
|
|
|
34
|
|
|
|
|
1536
|
|
5
|
34
|
|
|
34
|
|
11188
|
use IPC::Transit; |
|
34
|
|
|
|
|
134468
|
|
|
34
|
|
|
|
|
704
|
|
6
|
34
|
|
|
34
|
|
138
|
use Test::More; |
|
34
|
|
|
|
|
422
|
|
|
34
|
|
|
|
|
320
|
|
7
|
34
|
|
|
34
|
|
23184
|
use Message::Match qw(mmatch); |
|
34
|
|
|
|
|
16104
|
|
|
34
|
|
|
|
|
23726
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my @test_queues = qw/test_queue_full tqueue tqueue_out OtherModule Router OtherExternalModule tqueue_out_alt OtherModule_out YetAnotherExternalModule_out OtherExternalModule OtherModule YetAnotherExternalModule tqueue_out_secondary tqueue_out_tertiary OutOfBand MultiModule OtherExternalModule OtherModule Router test_alert_queue OtherExternalModule_out OtherModule_out Incrementer StatelessProducer Incrementer_out TaskDoesNotCompile/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head2 begin |
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
sub begin { |
14
|
34
|
50
|
|
34
|
1
|
356
|
if($^O !~ /linux/i) { |
15
|
0
|
|
|
|
|
0
|
ok 1, 'this only works on Linux, so we are just going to pass'; |
16
|
0
|
|
|
|
|
0
|
done_testing(); |
17
|
0
|
|
|
|
|
0
|
exit 0; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
# $IPC::Transit::config_dir = "/tmp/app_multimodule_transit_$$"; |
20
|
34
|
50
|
|
|
|
290
|
unlink 'test.conf' if -e 'test.conf'; |
21
|
34
|
|
|
|
|
85218
|
system 'rm -rf state'; |
22
|
34
|
|
|
|
|
998
|
clear_queue($_) for @test_queues; |
23
|
34
|
|
|
|
|
132708
|
unlink 'debug.out'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $program_pid; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 finish |
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
sub finish { |
31
|
1
|
50
|
|
1
|
1
|
18007642
|
unlink 'test.conf' if -e 'test.conf'; |
32
|
1
|
|
|
|
|
2934
|
system 'rm -rf state'; |
33
|
1
|
|
|
|
|
35
|
clear_queue($_) for @test_queues; |
34
|
1
|
|
|
|
|
3625
|
unlink 'debug.out'; |
35
|
1
|
|
|
|
|
2460
|
system "rm -rf /tmp/app_multimodule_transit_$$"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 run_program |
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
sub run_program { |
42
|
34
|
50
|
|
34
|
1
|
852
|
my $args = shift or die "App::MultiModule::Test::run_program: args required"; |
43
|
34
|
|
|
|
|
254
|
my @args = split /\s+/, $args; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# unshift @args, '-Ilib', 'bin/MultiModule'; #, '-T'; |
46
|
|
|
|
|
|
|
# push @args, "/tmp/app_multimodule_transit_$$"; |
47
|
34
|
|
|
|
|
27394
|
my $new_pid = fork; |
48
|
34
|
50
|
|
|
|
1602
|
die "App::MultiModule::Test::run_program: fork failed: $!" |
49
|
|
|
|
|
|
|
if not defined $new_pid; |
50
|
34
|
100
|
|
|
|
788
|
if(not $new_pid) { |
51
|
17
|
|
|
|
|
1359
|
$ENV{PATH}="bin/:$ENV{PATH}"; |
52
|
17
|
|
|
|
|
0
|
exec 'bin/MultiModule', @args; |
53
|
0
|
|
|
|
|
0
|
exit; |
54
|
|
|
|
|
|
|
} |
55
|
17
|
|
|
|
|
17002661
|
sleep 1; |
56
|
17
|
|
|
|
|
380
|
eval { |
57
|
17
|
50
|
|
|
|
2066
|
open my $fh, '<', "/proc/$new_pid/cmdline" |
58
|
|
|
|
|
|
|
or die "failed to open /proc/$new_pid/cmdline for reading: $!\n"; |
59
|
17
|
100
|
|
|
|
2167
|
read $fh, my $cmdline, 1024 |
60
|
|
|
|
|
|
|
or die "failed to read from /proc/$new_pid/cmdline: $!\n";; |
61
|
1
|
50
|
|
|
|
26
|
close $fh |
62
|
|
|
|
|
|
|
or die "failed to close /proc/$new_pid/cmdline: $!\n"; |
63
|
|
|
|
|
|
|
}; |
64
|
17
|
100
|
|
|
|
240
|
if($@) { |
65
|
16
|
|
|
|
|
3788
|
die "App::MultiModule::Test::run_program: failed: $@\n"; |
66
|
|
|
|
|
|
|
} |
67
|
1
|
|
|
|
|
5
|
$program_pid = $new_pid; |
68
|
1
|
|
|
|
|
25
|
return $program_pid; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 cleanly_exit |
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
sub cleanly_exit { |
74
|
0
|
|
|
0
|
1
|
0
|
my $qname = shift; |
75
|
0
|
|
|
|
|
0
|
ok IPC::Transit::send(qname => 'tqueue', message => { |
76
|
|
|
|
|
|
|
'.multimodule' => { |
77
|
|
|
|
|
|
|
control => [ |
78
|
|
|
|
|
|
|
{ type => 'cleanly_exit', |
79
|
|
|
|
|
|
|
exit_externals => 1, |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
], |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
}); |
84
|
0
|
|
|
|
|
0
|
sleep 6; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 term_program |
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
sub term_program { |
90
|
0
|
|
|
0
|
1
|
0
|
kill 15, $program_pid; |
91
|
0
|
|
|
|
|
0
|
sleep 4; |
92
|
0
|
|
|
|
|
0
|
kill 9, $program_pid; |
93
|
0
|
|
|
|
|
0
|
sleep 2; |
94
|
0
|
|
|
|
|
0
|
waitpid($program_pid, WNOHANG); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 fetch_alerts |
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
sub fetch_alerts { |
100
|
0
|
|
|
0
|
1
|
0
|
my $qname = shift; |
101
|
0
|
|
|
|
|
0
|
my $match = shift; |
102
|
0
|
|
|
|
|
0
|
my $got_levels = shift; |
103
|
0
|
|
|
|
|
0
|
my $how_long = shift; |
104
|
0
|
|
|
|
|
0
|
my %args = @_; |
105
|
0
|
|
|
|
|
0
|
my $founds = []; |
106
|
0
|
0
|
|
|
|
0
|
$got_levels = {} unless $got_levels; |
107
|
0
|
|
|
0
|
|
0
|
local $SIG{ALRM} = sub { die "timed out\n"; }; |
|
0
|
|
|
|
|
0
|
|
108
|
0
|
|
|
|
|
0
|
alarm $how_long; |
109
|
0
|
|
|
|
|
0
|
eval { |
110
|
0
|
|
|
|
|
0
|
while(1) { |
111
|
0
|
|
|
|
|
0
|
while(my $message = IPC::Transit::receive(qname => $qname)) { |
112
|
0
|
0
|
0
|
|
|
0
|
if( $message->{messages} and |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
113
|
|
|
|
|
|
|
ref $message->{messages} eq 'ARRAY' and |
114
|
|
|
|
|
|
|
$message->{messages}->[0] and |
115
|
|
|
|
|
|
|
$message->{messages}->[0]->{args} and |
116
|
|
|
|
|
|
|
$message->{messages}->[0]->{args}->{message}) { |
117
|
0
|
|
|
|
|
0
|
my $m = $message->{messages}->[0]->{args}->{message}; |
118
|
|
|
|
|
|
|
# print STDERR '$m=' . Data::Dumper::Dumper $m; |
119
|
0
|
0
|
|
|
|
0
|
if(mmatch($m, $match)) { |
120
|
0
|
0
|
|
|
|
0
|
$got_levels->{$m->{level}} = 0 |
121
|
|
|
|
|
|
|
unless $got_levels->{$m->{level}}; |
122
|
0
|
|
|
|
|
0
|
$got_levels->{$m->{level}}++; |
123
|
0
|
|
|
|
|
0
|
push @{$founds}, $m; |
|
0
|
|
|
|
|
0
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
}; |
129
|
0
|
|
|
|
|
0
|
return ($got_levels, $founds); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 clear_queue |
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
sub clear_queue { |
135
|
910
|
|
|
910
|
1
|
3303592
|
my $qname = shift; |
136
|
910
|
|
|
|
|
3042
|
IPC::Transit::receive(qname => $qname, nonblock => 1) for (1..100); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|