line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::MultiModule::Test::StatefulStream; |
2
|
|
|
|
|
|
|
$App::MultiModule::Test::StatefulStream::VERSION = '1.143160'; |
3
|
6
|
|
|
6
|
|
4728
|
use strict;use warnings; |
|
6
|
|
|
6
|
|
12
|
|
|
6
|
|
|
|
|
194
|
|
|
6
|
|
|
|
|
30
|
|
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
158
|
|
4
|
6
|
|
|
6
|
|
26
|
use Test::More; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
30
|
|
5
|
6
|
|
|
6
|
|
1246
|
use IPC::Transit; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
86
|
|
6
|
6
|
|
|
6
|
|
20
|
use Storable; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
302
|
|
7
|
6
|
|
|
6
|
|
28
|
use Message::Match qw(mmatch); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
244
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
24
|
use App::MultiModule::API; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
4428
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $inc; |
12
|
|
|
|
|
|
|
{ |
13
|
|
|
|
|
|
|
my $i; |
14
|
|
|
|
|
|
|
$inc = sub { |
15
|
|
|
|
|
|
|
$i = 1 unless $i; |
16
|
|
|
|
|
|
|
$i++; |
17
|
|
|
|
|
|
|
return $i; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 send |
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
26
|
0
|
|
|
|
|
|
my %args = @_; |
27
|
0
|
0
|
|
|
|
|
die "App::MultiModule::Test::StatefulStream::new: required argument 'task_name' not passed" |
28
|
|
|
|
|
|
|
unless $args{task_name}; |
29
|
|
|
|
|
|
|
# die "App::MultiModule::Test::StatefulStream::new: required argument 'program_pid' not passed" |
30
|
|
|
|
|
|
|
# unless $args{program_pid}; |
31
|
0
|
0
|
|
|
|
|
$args{timeout} = 40 unless $args{timeout}; |
32
|
0
|
0
|
|
|
|
|
$args{match} = { |
33
|
|
|
|
|
|
|
this => int rand 10000, |
34
|
|
|
|
|
|
|
that => $inc->(), |
35
|
|
|
|
|
|
|
} unless $args{match}; |
36
|
0
|
|
|
|
|
|
my $self = { |
37
|
|
|
|
|
|
|
increment => int rand 10000, |
38
|
|
|
|
|
|
|
task_name => $args{task_name}, |
39
|
|
|
|
|
|
|
program_pid => $args{program_pid}, |
40
|
|
|
|
|
|
|
current_id => 1, |
41
|
|
|
|
|
|
|
sent_messages => [], |
42
|
|
|
|
|
|
|
timeout => $args{timeout}, |
43
|
|
|
|
|
|
|
out_qname => $args{task_name} . '_out', |
44
|
|
|
|
|
|
|
match => $args{match}, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
bless ($self, $class); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 send |
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
sub send { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
0
|
|
|
|
|
|
my %args = @_; |
57
|
0
|
|
|
|
|
|
my $ct = int rand 10000; |
58
|
0
|
|
|
|
|
|
my $id = $self->{current_id}++; |
59
|
0
|
|
|
|
|
|
push @{$self->{sent_messages}}, { id => $id, ct => $ct }; |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $message = Storable::dclone $self->{match}; |
61
|
0
|
0
|
|
|
|
|
if($args{extras}) { |
62
|
0
|
|
|
|
|
|
while(my($key,$value) = each %{$args{extras}}) { |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$message->{$key} = $value; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
$message->{ct} = $ct; |
67
|
0
|
|
|
|
|
|
$message->{id} = $id; |
68
|
0
|
|
|
|
|
|
ok IPC::Transit::send(qname => $self->{task_name}, message => $message); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $incrementer_emit_ct; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 receive |
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
sub receive { |
76
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
my %args = @_; |
78
|
0
|
0
|
|
|
|
|
$incrementer_emit_ct = 1 unless defined $incrementer_emit_ct; |
79
|
0
|
|
|
|
|
|
my $ret; |
80
|
0
|
|
|
|
|
|
while(my $message = IPC::Transit::receive(qname => 'Incrementer_out', nonblock => 1)) { |
81
|
|
|
|
|
|
|
# print STDERR '$message->{emit_ct} == $incrementer_emit_ct' . "$message->{emit_ct} == $incrementer_emit_ct\n"; |
82
|
0
|
|
|
|
|
|
ok $message->{emit_ct} == $incrementer_emit_ct; |
83
|
0
|
|
|
|
|
|
$incrementer_emit_ct++; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
0
|
|
|
|
|
return undef unless scalar @{$self->{sent_messages}}; |
|
0
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $task_name = $self->{task_name}; |
87
|
0
|
|
|
|
|
|
my $out_qname = $self->{out_qname}; |
88
|
0
|
|
|
|
|
|
my $module_pid; |
89
|
0
|
|
|
|
|
|
eval { |
90
|
0
|
|
|
0
|
|
|
local $SIG{ALRM} = sub { die "timed out\n"; }; |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
alarm $self->{timeout}; |
92
|
0
|
|
|
|
|
|
ok my $msg = IPC::Transit::receive(qname => $out_qname); |
93
|
0
|
|
|
|
|
|
$ret = $msg; |
94
|
0
|
|
|
|
|
|
$module_pid = $msg->{module_pid}; |
95
|
0
|
0
|
|
|
|
|
if($args{match}) { |
96
|
|
|
|
|
|
|
# print STDERR 'msg: ' . Data::Dumper::Dumper $msg; |
97
|
|
|
|
|
|
|
# print STDERR 'match: ' . Data::Dumper::Dumper $args{match}; |
98
|
0
|
|
|
|
|
|
ok mmatch $msg, $args{match}; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
my $info = shift @{$self->{sent_messages}}; |
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
print STDERR '$msg->{ct} == $info->{ct}: ' . "$msg->{ct} : $info->{ct}\n" unless $msg->{ct} == $info->{ct}; |
103
|
0
|
|
|
|
|
|
ok $msg->{ct} == $info->{ct}; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
print STDERR '$msg->{id} == $info->{id}: ' . "$msg->{id} : $info->{id}\n" unless $msg->{id} == $info->{id}; |
106
|
0
|
|
|
|
|
|
ok $msg->{id} == $info->{id}; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
print '$msg->{my_ct} == $info->{ct} + $self->{increment}: ' . "$msg->{my_ct} : " . ($info->{ct} + $self->{increment}) . "\n" unless $msg->{my_ct} == $info->{ct} + $self->{increment}; |
109
|
0
|
|
|
|
|
|
ok $msg->{my_ct} == $info->{ct} + $self->{increment}; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if($self->{program_pid}) { |
112
|
0
|
0
|
0
|
|
|
|
if($args{type} and $args{type} eq 'external') { |
113
|
0
|
|
|
|
|
|
ok $msg->{module_pid} != $self->{program_pid}; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
0
|
|
|
|
if($args{type} and $args{type} eq 'internal') { |
116
|
0
|
|
|
|
|
|
ok $msg->{module_pid} == $self->{program_pid}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
}; |
120
|
0
|
|
|
|
|
|
alarm 0; |
121
|
0
|
0
|
|
|
|
|
ok not $@ unless $args{no_fail_exceptions}; |
122
|
0
|
0
|
|
|
|
|
if($@) { |
123
|
0
|
|
|
|
|
|
print STDERR "exception: $@\n"; |
124
|
0
|
|
|
|
|
|
print STDERR Data::Dumper::Dumper \%args; |
125
|
0
|
|
|
|
|
|
print STDERR "\$task_name=$task_name \$out_qname=$out_qname \$module_pid=$module_pid\n"; |
126
|
|
|
|
|
|
|
} else { |
127
|
0
|
|
|
|
|
|
print STDERR "OK: \$task_name=$task_name \$out_qname=$out_qname \$module_pid=$module_pid\n"; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
0
|
|
|
|
|
return undef if $@; |
130
|
0
|
|
|
|
|
|
return $ret; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
1; |