lib/DR/Tnt/Test/TntInstance.pm

filter: Statementstmt 26.8% 25 / 93 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 44.4% 8 / 18 Podpod 0.0% 0 / 9 totaltotal 19.5% 33 / 169 SCAR 59.0
CC
25
Cov
18%
start
156.0
new
72.0
kill
20.0
CRAP 366.5
« lib/DR/Tnt/LowLevel/Connector.pm ↑ Summary blib/lib/DR/Tnt/Test/TntInstance.pm »
1 31 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package DR::Tnt::Test::TntInstance;
6 31 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use File::Spec::Functions 'rel2abs', 'catfile';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 31 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub new {
13 0 ▶ my ($class, %opts) = @_;
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
14  
15 die "-lua or -make_lua option is not defined"
16 0 ▶ unless $opts{-lua} or $opts{-make_lua};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"-lua"} or $opts{"-make_lua"} 0 0 0
Condition0%0/3
$opts{"-lua"} or $opts{"-make_lua"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"-lua"} or $opts{"-make_lua"}
$opts{"-lua"} $opts{"-make_lua"}
Truth table0%0/3
A or B
A= $opts{"-lua"}B= $opts{"-make_lua"}
ABresult
1X1
011
000
17 0 ▶ $opts{-lua} = rel2abs $opts{-lua} if $opts{-lua};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"-lua"} 0 0 0
18 0 ▶ my $self = bless \%opts => ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
19  
20  
21 0 ▶ if ($self->{-dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'-dir'}) { } 0 0 0
22 0 ▶ die "$self->{-dir} not found" unless -d $self->{-dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->{"-dir"} 0 0 0
23 } else {
24 0 $self->{-dir} = File::Temp::tempdir;
25 0 $self->{-clean} = [ $self->{-dir} ];
26 }
27  
28 0 $self->{-log} = rel2abs catfile $self->{-dir}, 'tarantool.log';
29 0 $self->{-log_seek} = 0;
30 0 ▶ if (-r $self->{-log}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $self->{"-log"}) 0 0 0
31 0 open my $fh, '<', $self->{-log};
32 0 seek $fh, 0, 2;
33 0 $self->{-log_seek} = tell $fh;
34 0 close $fh;
35 }
36  
37  
38 0 $self->start;
39 }
40  
41  
42 sub start {
43 0 ▶ my ($self) = @_;
Subroutine start: not called CC=12 SCAR=50.5
Pod undocumented
44 0 ▶ if ($self->{pid} = fork) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pid"} = fork) 0 0 0
45 0 for (1 .. 10) {
46 0 Time::HiRes::sleep .1;
47 0 ▶ last unless $self->{-port};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"-port"} 0 0 0
48
49 next unless IO::Socket::INET->new(
50 PeerHost => '127.0.0.1',
51 PeerPort => $self->{-port},
52 0 ▶ Proto => 'tcp',
Branch: 2 branches
BranchTrueFalseTotal
unless "IO::Socket::INET"->new("PeerHost", "127.0.0.1", "PeerPort", $self->{"-port"}, "Proto", "tcp", $^O eq "MSWin32" ? () : ("ReuseAddr", 1)) 0 0 0
$^O eq 'MSWin32' ? : 0 0 0
53 (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
54 );
55 0 ▶ last if $self->log =~ /entering the event loop/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->log =~ /entering the event loop/ 0 0 0
56 }
57  
58 0 return $self;
59 }
60
61 0 for (open my $fh, '>>', $self->{-log}) {
62 0 POSIX::dup2(fileno($fh), fileno(STDOUT));
63 0 POSIX::dup2(fileno($fh), fileno(STDERR));
64 0 close $fh;
65 }
66  
67 0 ▶ unless ($self->{-lua}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"-lua"}) 0 0 0
68 0 $self->{-lua} = catfile $self->{-dir}, 'make_lua.lua';
69 open my $fh, '>:raw', $self->{-lua}
70 0 ▶ or warn "Can't create $self->{-lua}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:raw", $self->{"-lua"} or warn qq[Can't create $self->{"-lua"}: $!\n] 0 0 0
71 0 my $lua = $self->{-make_lua};
72 0 ▶ utf8::encode $lua if utf8::is_utf8 $lua;
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($lua) 0 0 0
73 0 print $fh $lua;
74 0 close $fh;
75 }
76  
77 0 chdir $self->{-dir};
78 0 ▶ if ($self->port) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->port) 0 0 0
79 0 $ENV{PRIMARY_PORT} = $self->port;
80 }
81 0 $ENV{WORK_DIR} = $self->{-dir};
82 0 exec tarantool => $self->{-lua};
83 0 die "Can't start tarantool";
84 }
85  
86 sub stop {
87 0 ▶ my ($self) = @_;
Subroutine stop: not called CC=1 SCAR=6.9
Pod undocumented
88 0 $self->kill('TERM');
89 }
90  
91 0 ▶sub port { $_[0]->{-port} }
Subroutine port: not called CC=1 SCAR=6.9
Pod undocumented
92 sub is_started {
93 0 ▶ return $_[0]->log =~ /entering the event loop/;
Subroutine is_started: not called CC=1 SCAR=6.9
Pod undocumented
94 }
95  
96 sub log {
97 0 ▶ my ($self) = @_;
Subroutine log: not called CC=2 SCAR=17.9
Pod undocumented
98 0 ▶ return '' unless -r $self->{-log};
Branch: 1 branch
BranchTrueFalseTotal
unless -r $self->{"-log"} 0 0 0
99 0 open my $fh, '<', $self->{-log};
100 0 seek $fh, 0, $self->{-log_seek};
101 0 local $/;
102 0 my $data = <$fh>;
103 0 return $data;
104 }
105  
106 sub clean {
107 0 ▶ my ($self) = @_;
Subroutine clean: not called CC=3 SCAR=24.8
Pod undocumented
108 0 ▶ return unless $self->{-clean};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"-clean"} 0 0 0
109 0 for (@{ $self->{-clean} }) {
110 0 system "rm -fr $_";
111 }
112 }
113  
114 0 ▶sub pid { $_[0]->{pid} };
Subroutine pid: not called CC=1 SCAR=6.9
Pod undocumented
115  
116 sub kill {
117 0 ▶ my ($self, $sig) = @_;
Subroutine kill: not called CC=4 SCAR=30.0
Pod undocumented
118 0 ▶ return unless $self->pid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->pid 0 0 0
119 0 ▶ $sig ||= 'TERM';
Condition0%0/2
$sig ||= "TERM"
l!l
00
MC/DC0%0/1
$sig ||= "TERM"
$sig
Truth table0%0/2
A
A= $sig
Aresult
11
00
120 0 ▶ if (kill $sig, $self->pid) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::kill $sig, $self->pid) { } 0 0 0
121 0 waitpid $self->pid, 0;
122 } else {
123 0 warn sprintf "Can't kill -$sig %s\n", $self->pid;
124 }
125 0 delete $self->{pid};
126 }
127  
128 sub DESTROY {
129 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=1 SCAR=6.9
130 0 $self->kill('KILL');
131 0 $self->clean;
132 }
133  
134  
135 31 1;
« lib/DR/Tnt/LowLevel/Connector.pm ↑ Summary blib/lib/DR/Tnt/Test/TntInstance.pm »