line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
31
|
|
|
31
|
|
218
|
use utf8; |
|
31
|
|
|
|
|
70
|
|
|
31
|
|
|
|
|
174
|
|
2
|
31
|
|
|
31
|
|
1053
|
use strict; |
|
31
|
|
|
|
|
67
|
|
|
31
|
|
|
|
|
775
|
|
3
|
31
|
|
|
31
|
|
177
|
use warnings; |
|
31
|
|
|
|
|
61
|
|
|
31
|
|
|
|
|
1284
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package DR::Tnt::Test::TntInstance; |
6
|
31
|
|
|
31
|
|
22962
|
use File::Temp; |
|
31
|
|
|
|
|
720226
|
|
|
31
|
|
|
|
|
2768
|
|
7
|
31
|
|
|
31
|
|
8627
|
use File::Spec::Functions 'rel2abs', 'catfile'; |
|
31
|
|
|
|
|
18351
|
|
|
31
|
|
|
|
|
2094
|
|
8
|
31
|
|
|
31
|
|
13479
|
use Time::HiRes (); |
|
31
|
|
|
|
|
37515
|
|
|
31
|
|
|
|
|
862
|
|
9
|
31
|
|
|
31
|
|
14821
|
use IO::Socket::INET; |
|
31
|
|
|
|
|
390228
|
|
|
31
|
|
|
|
|
240
|
|
10
|
31
|
|
|
31
|
|
35545
|
use POSIX; |
|
31
|
|
|
|
|
221053
|
|
|
31
|
|
|
|
|
199
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my ($class, %opts) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
die "-lua or -make_lua option is not defined" |
16
|
0
|
0
|
0
|
|
|
|
unless $opts{-lua} or $opts{-make_lua}; |
17
|
0
|
0
|
|
|
|
|
$opts{-lua} = rel2abs $opts{-lua} if $opts{-lua}; |
18
|
0
|
|
0
|
|
|
|
my $self = bless \%opts => ref($class) || $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if ($self->{-dir}) { |
22
|
0
|
0
|
|
|
|
|
die "$self->{-dir} not found" unless -d $self->{-dir}; |
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
|
0
|
|
|
|
|
if (-r $self->{-log}) { |
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
|
|
|
0
|
0
|
|
my ($self) = @_; |
44
|
0
|
0
|
|
|
|
|
if ($self->{pid} = fork) { |
45
|
0
|
|
|
|
|
|
for (1 .. 10) { |
46
|
0
|
|
|
|
|
|
Time::HiRes::sleep .1; |
47
|
0
|
0
|
|
|
|
|
last unless $self->{-port}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
next unless IO::Socket::INET->new( |
50
|
|
|
|
|
|
|
PeerHost => '127.0.0.1', |
51
|
|
|
|
|
|
|
PeerPort => $self->{-port}, |
52
|
0
|
0
|
|
|
|
|
Proto => 'tcp', |
|
|
0
|
|
|
|
|
|
53
|
|
|
|
|
|
|
(($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), |
54
|
|
|
|
|
|
|
); |
55
|
0
|
0
|
|
|
|
|
last if $self->log =~ /entering the event loop/; |
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
|
0
|
|
|
|
|
unless ($self->{-lua}) { |
68
|
0
|
|
|
|
|
|
$self->{-lua} = catfile $self->{-dir}, 'make_lua.lua'; |
69
|
|
|
|
|
|
|
open my $fh, '>:raw', $self->{-lua} |
70
|
0
|
0
|
|
|
|
|
or warn "Can't create $self->{-lua}: $!\n"; |
71
|
0
|
|
|
|
|
|
my $lua = $self->{-make_lua}; |
72
|
0
|
0
|
|
|
|
|
utf8::encode $lua if utf8::is_utf8 $lua; |
73
|
0
|
|
|
|
|
|
print $fh $lua; |
74
|
0
|
|
|
|
|
|
close $fh; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
chdir $self->{-dir}; |
78
|
0
|
0
|
|
|
|
|
if ($self->port) { |
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
|
|
|
0
|
0
|
|
my ($self) = @_; |
88
|
0
|
|
|
|
|
|
$self->kill('TERM'); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
0
|
|
sub port { $_[0]->{-port} } |
92
|
|
|
|
|
|
|
sub is_started { |
93
|
0
|
|
|
0
|
0
|
|
return $_[0]->log =~ /entering the event loop/; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub log { |
97
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
98
|
0
|
0
|
|
|
|
|
return '' unless -r $self->{-log}; |
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
|
|
|
0
|
0
|
|
my ($self) = @_; |
108
|
0
|
0
|
|
|
|
|
return unless $self->{-clean}; |
109
|
0
|
|
|
|
|
|
for (@{ $self->{-clean} }) { |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
system "rm -fr $_"; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
0
|
0
|
|
sub pid { $_[0]->{pid} }; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub kill { |
117
|
0
|
|
|
0
|
0
|
|
my ($self, $sig) = @_; |
118
|
0
|
0
|
|
|
|
|
return unless $self->pid; |
119
|
0
|
|
0
|
|
|
|
$sig ||= 'TERM'; |
120
|
0
|
0
|
|
|
|
|
if (kill $sig, $self->pid) { |
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
|
|
|
0
|
|
|
my ($self) = @_; |
130
|
0
|
|
|
|
|
|
$self->kill('KILL'); |
131
|
0
|
|
|
|
|
|
$self->clean; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |