blib/lib/DR/Tarantool/StartTest.pm

filter: Statementstmt 43.1% 92 / 213 Branchbran 18.1% 20 / 110 Conditioncond 30.0% 6 / 20 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 60.0% 21 / 35 Podpod 60.0% 9 / 15 totaltotal 36.8% 149 / 404 CC 70 SCAR 42.1
CC
70
Cov
34%
_start_tarantool
253.1
_restart
90.0
compare_versions
56.0
CRAP 67.7
« blib/lib/DR/Tarantool/LLSyncClient.pm ↑ Summary blib/lib/DR/Tarantool/MsgPack/LLClient.pm »
1 11 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package DR::Tarantool::StartTest;
6 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use File::Temp qw(tempfile tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use File::Path 'rmtree';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use File::Spec::Functions qw(catfile rel2abs);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use List::MoreUtils 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 =head1 NAME
17  
18 DR::Tarantool::StartTest - finds and starts Tarantool on free port.
19  
20 =head1 SYNOPSIS
21  
22 my $t = run DR::Tarantool::StartTest ( cfg => $file_spaces_cfg );
23  
24 =head1 DESCRIPTION
25  
26 The module tries to find and then to start B<tarantool_box>.
27  
28 The module is used inside tests.
29  
30  
31 =head1 METHODS
32  
33 =head2 run
34  
35 Constructor. Receives the following arguments:
36  
37 =over
38  
39 =item cfg
40  
41 path to tarantool.cfg
42  
43 =back
44  
45 =cut
46  
47  
48 sub compare_versions($$) {
49 0 ▶ my ($v1, $v2) = @_;
Subroutine compare_versions: not called CC=7 SCAR=40.3
Pod undocumented
50 0 my @v1 = split /\./, $v1;
51 0 my @v2 = split /\./, $v2;
52  
53 0 ▶ for (0 .. (@v1 < @v2 ? $#v1 : $#v2)) {
Branch: 1 branch
BranchTrueFalseTotal
@v1 < @v2 ? : 0 0 0
54 0 ▶ return 'gt' if $v1[$_] > $v2[$_];
Branch: 1 branch
BranchTrueFalseTotal
if $v1[$_] > $v2[$_] 0 0 0
55 0 ▶ return 'lt' if $v1[$_] < $v2[$_];
Branch: 1 branch
BranchTrueFalseTotal
if $v1[$_] < $v2[$_] 0 0 0
56 }
57 0 ▶ return 'gt' if @v1 > @v2;
Branch: 1 branch
BranchTrueFalseTotal
if @v1 > @v2 0 0 0
58 0 ▶ return 'lt' if @v1 < @v2;
Branch: 1 branch
BranchTrueFalseTotal
if @v1 < @v2 0 0 0
59 0 return 'eq';
60 }
61  
62  
63 =head2 is_version(VERSION[, FAMILY])
64  
65 return true if tarantool_box is found and its version is more than L<VERSION>.
66  
67 FAMILY can be:
68  
69 =over
70  
71 =item B<1> (default)
72  
73 For tarantool < 1.6.
74  
75 =item B<2>
76  
77 For tarantool >= 1.6.
78  
79 =back
80  
81 =cut
82  
83 sub is_version($;$) {
84 9 ▶ my ($version, $family) = @_;
Subroutine is_version: called CC=10 SCAR=32.0
Pod documented
85  
86 9 my $box;
87 9 ▶ $family ||= 1;
Condition100%2/2
$family ||= 1
l!l
45
MC/DC100%1/1
$family ||= 1
$family
Truth table100%2/2
A
A= $family
Aresult
11
00
88  
89 9 ▶ croak "Unknown family: $family" unless any { $family == $_ } 1, 2;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $family == $_; } , 1, 2) 0 9 9
90  
91 9 ▶ if ($family == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 1) { } 9 0 9
92 9 ▶ $box = $ENV{TARANTOOL_BOX} || 'tarantool_box';
Condition50%1/2
$ENV{'TARANTOOL_BOX'} || 'tarantool_box'
l!l
09
MC/DC0%0/1
$ENV{'TARANTOOL_BOX'} || 'tarantool_box'
$ENV{'TARANTOOL_BOX'}
Truth table50%1/2
A
A= $ENV{'TARANTOOL_BOX'}
Aresult
11
00
93 } else {
94 0 ▶ $box = $ENV{TARANTOOL_BOX} || 'tarantool';
Condition0%0/2
$ENV{'TARANTOOL_BOX'} || 'tarantool'
l!l
00
MC/DC0%0/1
$ENV{'TARANTOOL_BOX'} || 'tarantool'
$ENV{'TARANTOOL_BOX'}
Truth table0%0/2
A
A= $ENV{'TARANTOOL_BOX'}
Aresult
11
00
95 }
96
97 9 my $str;
98 {
99 9 ▶ local $SIG{__WARN__} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
100 9 $str = `$box -V`;
101 }
102  
103 9 ▶ return 0 unless $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 9 0 9
104 0 ▶ return 0 if $str =~ /^tarantool client, version/;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^tarantool client, version/ 0 0 0
105 0 my ($vt) = $str =~ /^Tarantool:?\s+(\d(?:\.\d+)+).*\s*$/s;
106 0 ▶ return 0 unless $vt;
Branch: 1 branch
BranchTrueFalseTotal
unless $vt 0 0 0
107 0 my $res = compare_versions $version, $vt;
108 0 ▶ return 0 unless any { $_ eq $res } 'eq', 'lt';
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $res; } , "eq", "lt") 0 0 0
109 0 return 1;
110 }
111  
112 sub run {
113 4 ▶ my ($module, %opts) = @_;
Subroutine run: called CC=7 SCAR=20.1
Pod documented
114  
115 4 ▶ my $cfg_file = delete $opts{cfg} or croak "config file not defined";
Branch: 1 branch
BranchTrueFalseTotal
my $cfg_file = delete $opts{"cfg"} or croak("config file not defined") 0 4 4
116 4 ▶ croak "File not found" unless -r $cfg_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $cfg_file 0 4 4
117 4 ▶ open my $fh, '<:encoding(UTF-8)', $cfg_file or die "$@\n";
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $cfg_file or die "$@\n" 0 4 4
118 4 local $/;
119 4 my $cfg = <$fh>;
120  
121 4 ▶ my $family = $opts{family} || 1;
Condition50%1/2
$opts{'family'} || 1
l!l
04
MC/DC0%0/1
$opts{'family'} || 1
$opts{'family'}
Truth table50%1/2
A
A= $opts{'family'}
Aresult
11
00
122 4 ▶ croak "Unknown family: $family" unless any { $family == $_ } 1, 2;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $family == $_; } , 1, 2) 0 4 4
123  
124 4 my %self = (
125 admin_port => $module->_find_free_port,
126 primary_port => $module->_find_free_port,
127 secondary_port => $module->_find_free_port,
128 cfg_data => $cfg,
129 master => $$,
130 cwd => getcwd,
131 add_opts => \%opts,
132 family => $family,
133 );
134  
135 4 ▶ $opts{script_dir} = rel2abs $opts{script_dir} if $opts{script_dir};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"script_dir"} 1 3 4
136  
137 4 my $self = bless \%self => $module;
138 4 $self->_start_tarantool;
139 0 $self;
140 }
141  
142  
143 sub family {
144 12 ▶ my ($self) = @_;
Subroutine family: called CC=1 SCAR=0.0
Pod undocumented
145 12 return $self->{family};
146 }
147  
148  
149 =head2 started
150  
151 Return true if Tarantool is found and started
152  
153 =cut
154  
155 sub started {
156 0 ▶ my ($self) = @_;
Subroutine started: not called CC=1 SCAR=6.9
Pod documented
157 0 return $self->{started};
158 }
159  
160  
161 =head2 log
162  
163 Return Tarantool logs
164  
165 =cut
166  
167 sub log {
168 0 ▶ my ($self) = @_;
Subroutine log: not called CC=3 SCAR=24.8
Pod documented
169 0 ▶ return '' unless $self->{log} and -r $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"log"} and -r $self->{"log"} 0 0 0
Condition0%0/3
$self->{"log"} and -r $self->{"log"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"log"} and -r $self->{"log"}
$self->{"log"} -r $self->{"log"}
Truth table0%0/3
A and B
A= $self->{"log"}B= -r $self->{"log"}
ABresult
0X0
100
111
170 0 open my $fh, '<encoding(UTF-8)', $self->{log};
171 0 local $/;
172 0 my $l = <$fh>;
173 0 return $l;
174 }
175  
176 sub admin {
177 0 ▶ my ($self, @cmd) = @_;
Subroutine admin: not called CC=6 SCAR=37.4
Pod undocumented
178 0 $cmd[-1] =~ s/\s*$/\n/;
179 0 my $cmd = join ' ' => @cmd;
180  
181 0 ▶ my $s = IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
182 PeerHost => '127.0.0.1',
183 PeerPort => $self->admin_port,
184 Proto => 'tcp',
185 (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
186 );
187  
188 0 ▶ croak "Can't connect to admin port: $!" unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 0 0
189 0 print $s $cmd;
190 0 my @lines;
191 0 ▶ while(<$s>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $s)) 0 0 0
192 0 s/\s*$//;
193 0 ▶ next if $_ eq '---';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "---" 0 0 0
194 0 ▶ last if $_ eq '...';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "..." 0 0 0
195 0 push @lines => $_;
196 }
197 0 close $s;
198 0 return @lines;
199 }
200  
201 sub _start_tarantool {
202 4 ▶ my ($self) = @_;
Subroutine _start_tarantool: called CC=20 SCAR=55.3
203 4 ▶ if ($ENV{TARANTOOL_TEMPDIR}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'TARANTOOL_TEMPDIR'}) { } 0 4 4
204 0 $self->{temp} = $ENV{TARANTOOL_TEMPDIR};
205 0 $self->{dont_unlink_temp} = 1;
206 0 ▶ rmtree $self->{temp} if -d $self->{temp};
Branch: 1 branch
BranchTrueFalseTotal
if -d $self->{"temp"} 0 0 0
207 0 mkdir $self->{temp};
208 } else {
209 4 $self->{temp} = tempdir;
210 }
211  
212 4 ▶ if ($self->family) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->family) { } 4 0 4
213 4 $self->{cfg} = catfile $self->{temp}, 'tarantool.cfg';
214 } else {
215 0 $self->{cfg} = catfile $self->{temp}, 'box.lua';
216 }
217 4 $self->{log} = catfile $self->{temp}, 'tarantool.log';
218 4 $self->{pid} = catfile $self->{temp}, 'tarantool.pid';
219 4 $self->{core} = catfile $self->{temp}, 'core';
220  
221  
222  
223 4 ▶ if ($self->family == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->family == 1) { } 4 0 4
224 4 ▶ croak "Available tarantool is not valid (is_version '1.4.0')"
Branch: 1 branch
BranchTrueFalseTotal
unless &is_version("1.4.0", scalar $self->family) 4 0 4
225 unless is_version '1.4.0', $self->family;
226 } else {
227 0 ▶ croak "Available tarantool is not valid (is_version '1.4.0')"
Branch: 1 branch
BranchTrueFalseTotal
unless &is_version("1.6.0", scalar $self->family) 0 0 0
228 unless is_version '1.6.0', $self->family;
229 }
230  
231  
232 0 $self->{config_body} = $self->{cfg_data};
233 0 ▶ if ($self->family == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->family == 1) { } 0 0 0
234 0 $self->{config_body} .= "\n\n";
235 0 $self->{config_body} .= "slab_alloc_arena = 1.1\n";
236 0 $self->{config_body} .= sprintf "pid_file = %s\n", $self->{pid};
237 0 ▶ $self->{box} = $ENV{TARANTOOL_BOX} || 'tarantool_box';
Condition0%0/2
$ENV{'TARANTOOL_BOX'} || 'tarantool_box'
l!l
00
MC/DC0%0/1
$ENV{'TARANTOOL_BOX'} || 'tarantool_box'
$ENV{'TARANTOOL_BOX'}
Truth table0%0/2
A
A= $ENV{'TARANTOOL_BOX'}
Aresult
11
00
238  
239 $self->{config_body} .= sprintf "%s = %s\n", $_, $self->{$_}
240 0 for (qw(admin_port primary_port secondary_port));
241  
242 $self->{config_body} .=
243 0 sprintf qq{logger = "cat >> %s"\n}, $self->{log};
244  
245 0 for (keys %{ $self->{add_opts} }) {
246 0 my $v = $self->{add_opts}{ $_ };
247  
248 0 ▶ if ($v =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^\d+$/) { } 0 0 0
249 0 $self->{config_body} .= sprintf qq{%s = %s\n}, $_, $v;
250 } else {
251 0 $self->{config_body} .= sprintf qq{%s = "%s"\n}, $_, $v;
252 }
253 }
254 } else {
255 0 ▶ $self->{box} = $ENV{TARANTOOL_BOX} || 'tarantool';
Condition0%0/2
$ENV{'TARANTOOL_BOX'} || 'tarantool'
l!l
00
MC/DC0%0/1
$ENV{'TARANTOOL_BOX'} || 'tarantool'
$ENV{'TARANTOOL_BOX'}
Truth table0%0/2
A
A= $ENV{'TARANTOOL_BOX'}
Aresult
11
00
256 0 for ($self->{config_body}) {
257 0 ▶ if (/admin_port\s*=/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/admin_port\s*=/) { } 0 0 0
258 0 s{admin_port\s*=\s*['"]?\d+['"]}
259 0 /admin_port = @{[$self->admin_port]}/;
260 } else {
261 0 s<box\.cfg\s*\(?\s*\{>
262 0 /$& admin_port = @{[$self->admin_port]},/;
263 }
264 0 ▶ if (/primary_port\s*=/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/primary_port\s*=/) { } 0 0 0
265 0 s{primary_port\s*=\s*['"]?\d+['"]}
266 0 /primary_port = @{[$self->primary_port]}/;
267 } else {
268 0 s<box\.cfg\s*\(?\s*\{>
269 0 /$& primary_port = @{[$self->primary_port]},/;
270 }
271 }
272 }
273  
274 0 ▶ return unless open my $fh, '>:encoding(UTF-8)', $self->{cfg};
Branch: 1 branch
BranchTrueFalseTotal
unless open my $fh, ">:encoding(UTF-8)", $self->{"cfg"} 0 0 0
275 0 print $fh $self->{config_body};
276 0 close $fh;
277  
278 0 chdir $self->{temp};
279  
280 0 ▶ if ($self->family == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->family == 1) 0 0 0
281 0 system "$self->{box} -c $self->{cfg} ".
282 "--check-config >> $self->{log} 2>&1";
283 0 ▶ goto EXIT if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
284  
285 0 system "$self->{box} -c $self->{cfg} --init-storage ".
286 ">> $self->{log} 2>&1";
287 0 ▶ goto EXIT if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
288 }
289 0 $self->_restart;
290 EXIT:
291 0 chdir $self->{cwd};
292  
293 }
294  
295 sub _restart {
296 0 ▶ my ($self) = @_;
Subroutine _restart: not called CC=9 SCAR=45.0
297  
298 0 ▶ unless ($self->{child} = fork) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"child"} = fork) 0 0 0
299 0 chdir $self->{temp};
300 0 ▶ die "Can't fork: $!" unless defined $self->{child};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"child"} 0 0 0
301 0 POSIX::setsid();
302 0 ▶ if ($self->family == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->family == 1) { } 0 0 0
303 0 exec "ulimit -c unlimited; ".
304 "exec $self->{box} -c $self->{cfg} >> $self->{log} 2>&1";
305 } else {
306 0 exec "ulimit -c unlimited; ".
307 "exec $self->{box} $self->{cfg} >> $self->{log} 2>&1";
308 }
309 0 die "Can't start $self->{box}: $!\n";
310 }
311  
312 0 $self->{started} = 1;
313  
314  
315 # wait for starting Tarantool
316 0 ▶ for (my $i = 0; $i < 100; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 100) 0 0 0
317 0 ▶ last if IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
if "IO::Socket::INET"->new("PeerAddr", "127.0.0.1", "PeerPort", $self->primary_port) 0 0 0
318 PeerAddr => '127.0.0.1', PeerPort => $self->primary_port
319 );
320  
321 0 sleep 0.01;
322 }
323  
324 0 ▶ for (my $i = 0; $i < 100; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 100) 0 0 0
325 0 ▶ last if $self->log =~ /entering event loop/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->log =~ /entering event loop/ 0 0 0
326 0 sleep 0.01;
327 }
328  
329 0 ▶ sleep 1 unless $self->log =~ /entering event loop/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->log =~ /entering event loop/ 0 0 0
330 }
331  
332 sub restart {
333 0 ▶ my ($self) = @_;
Subroutine restart: not called CC=1 SCAR=6.9
Pod undocumented
334 0 $self->kill('KILL');
335 0 $self->_restart;
336 }
337  
338 =head2 primary_port
339  
340 Return Tarantool primary port
341  
342 =cut
343  
344 0 ▶sub primary_port { return $_[0]->{primary_port} }
Subroutine primary_port: not called CC=1 SCAR=6.9
Pod documented
345  
346  
347 =head2 admin_port
348  
349 Return Tarantool admin port
350  
351 =cut
352  
353 0 ▶sub admin_port { return $_[0]->{admin_port} }
Subroutine admin_port: not called CC=1 SCAR=6.9
Pod documented
354  
355  
356 =head2 tarantool_pid
357  
358 Return B<PID>
359  
360 =cut
361  
362 0 ▶sub tarantool_pid { return $_[0]->{child} }
Subroutine tarantool_pid: not called CC=1 SCAR=6.9
Pod documented
363  
364  
365 =head2 kill
366  
367 Kills Tarantool
368  
369 =cut
370  
371 sub kill :method {
372 4 ▶ my ($self, $signame) = @_;
Subroutine kill: called CC=3 SCAR=13.5
Pod documented
373  
374 4 ▶ $signame ||= 'TERM';
Condition50%1/2
$signame ||= "TERM"
l!l
04
MC/DC0%0/1
$signame ||= "TERM"
$signame
Truth table50%1/2
A
A= $signame
Aresult
11
00
375 4 ▶ if ($self->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"child"}) 0 4 4
376 0 kill $signame => $self->{child};
377 0 waitpid $self->{child}, 0;
378 0 delete $self->{child};
379 }
380 4 $self->{started} = 0;
381 }
382  
383  
384 =head2 is_dead
385  
386 Return true if child Tarantool process is dead.
387  
388 =cut
389  
390 sub is_dead {
391 0 ▶ my ($self) = @_;
Subroutine is_dead: not called CC=3 SCAR=24.8
Pod documented
392 0 ▶ return 1 unless $self->{child};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"child"} 0 0 0
393 0 ▶ return 0 if 0 < kill 0 => $self->{child};
Branch: 1 branch
BranchTrueFalseTotal
if 0 < CORE::kill(0, $self->{"child"}) 0 0 0
394 0 return 1;
395 }
396  
397 =head2 DESTROY
398  
399 Destructor. Kills tarantool, removes temporary files.
400  
401 =cut
402  
403 sub DESTROY {
404 4 ▶ my ($self) = @_;
Subroutine DESTROY: called CC=6 SCAR=22.3
405 4 local $?;
406 4 chdir $self->{cwd};
407 4 ▶ return unless $self->{master} == $$;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"master"} == $$ 0 4 4
408  
409 4 ▶ if (-r $self->{core}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $self->{"core"}) 0 4 4
410 0 ▶ warn "Tarantool was coredumped\n" if -r $self->{core};
Branch: 1 branch
BranchTrueFalseTotal
if -r $self->{"core"} 0 0 0
411 0 system "echo bt|gdb $self->{box} $self->{core}";
412 }
413  
414 4 $self->kill;
415 4 ▶ rmtree $self->{temp} if $self->{temp} and !$self->{dont_unlink_temp};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"temp"} and not $self->{"dont_unlink_temp"} 4 0 4
Condition33%1/3
$self->{"temp"} and not $self->{"dont_unlink_temp"}
!ll&&!rl&&r
004
MC/DC0%0/2
$self->{"temp"} and not $self->{"dont_unlink_temp"}
$self->{"temp"} not $self->{"dont_unlink_temp"}
Truth table33%1/3
A and not(B)
A= $self->{"temp"}B= not $self->{"dont_unlink_temp"}
ABresult
0X0
100
111
416 }
417  
418  
419 sub temp_dir {
420 0 ▶ my ($self) = @_;
Subroutine temp_dir: not called CC=1 SCAR=6.9
Pod undocumented
421 0 return $self->{temp};
422 }
423  
424  
425 sub clean_xlogs {
426 0 ▶ my ($self) = @_;
Subroutine clean_xlogs: not called CC=3 SCAR=24.8
Pod undocumented
427 0 ▶ return unless $self->{temp};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"temp"} 0 0 0
428 0 my @xlogs = glob catfile $self->{temp}, '*.xlog';
429 0 unlink for @xlogs;
430 }
431  
432 {
433 11 my %busy_ports;
434  
435 sub _find_free_port {
436  
437 13 ▶ while( 1 ) {
Subroutine _find_free_port: called CC=4 SCAR=14.6
438 13 my $port = 10000 + int rand 30000;
439 13 ▶ next if exists $busy_ports{ $port };
Branch: 1 branch
BranchTrueFalseTotal
if exists $busy_ports{$port} 0 13 13
440 13 ▶ next unless IO::Socket::INET->new(
Branch: 2 branches
BranchTrueFalseTotal
unless "IO::Socket::INET"->new("Listen", 5, "LocalAddr", "127.0.0.1", "LocalPort", $port, "Proto", "tcp", $^O eq "MSWin32" ? () : ("ReuseAddr", 1)) 0 13 13
$^O eq 'MSWin32' ? : 0 13 13
441 Listen => 5,
442 LocalAddr => '127.0.0.1',
443 LocalPort => $port,
444 Proto => 'tcp',
445 (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
446 );
447 13 return $busy_ports{ $port } = $port;
448 }
449 }
450 }
451  
452 =head1 COPYRIGHT AND LICENSE
453  
454 Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org>
455 Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru>
456  
457 This program is free software, you can redistribute it and/or
458 modify it under the terms of the Artistic License.
459  
460 =head1 VCS
461  
462 The project is placed git repo on github:
463 L<https://github.com/dr-co/dr-tarantool/>.
464  
465 =cut
466  
467 11 1;
« blib/lib/DR/Tarantool/LLSyncClient.pm ↑ Summary blib/lib/DR/Tarantool/MsgPack/LLClient.pm »