line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Consul::Simple::Test; |
2
|
|
|
|
|
|
|
$Consul::Simple::Test::VERSION = '1.142390'; |
3
|
|
|
|
|
|
|
my $consul_data_dir = '/tmp/consul_data_' . $$; |
4
|
|
|
|
|
|
|
our $consul_daemon_pid; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub init_tests { |
7
|
8
|
|
|
8
|
0
|
5444
|
my $can_test = init_server(); |
8
|
4
|
50
|
|
|
|
100
|
if(not $can_test) { |
9
|
0
|
|
|
|
|
0
|
print STDERR "#full tests can only be run on Linux or MacOS(Darwin) x86_64. Skipping all.\n"; |
10
|
0
|
|
|
|
|
0
|
exit 0; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init_server { |
15
|
8
|
|
|
8
|
0
|
109006
|
my $uname = `uname 2>&1`; |
16
|
8
|
|
|
|
|
228
|
chomp $uname; |
17
|
8
|
50
|
33
|
|
|
696
|
if($uname ne 'Linux' and $uname ne 'Darwin') { |
18
|
0
|
|
|
|
|
0
|
return 0; |
19
|
|
|
|
|
|
|
} |
20
|
8
|
|
|
|
|
79386
|
my $arch = `uname -m 2>&1`; |
21
|
8
|
|
|
|
|
412
|
chomp $arch; |
22
|
8
|
50
|
|
|
|
364
|
if($arch ne 'x86_64') { |
23
|
0
|
|
|
|
|
0
|
return 0; |
24
|
|
|
|
|
|
|
} |
25
|
8
|
|
50
|
|
|
1842
|
mkdir $consul_data_dir || return 0; |
26
|
8
|
|
|
|
|
26645
|
my $new_pid = fork; |
27
|
8
|
50
|
|
|
|
814
|
return 0 if not defined $new_pid; #fork failed. (!??) |
28
|
8
|
100
|
|
|
|
287
|
if(not $new_pid) { #child |
29
|
4
|
|
|
|
|
338
|
my $consul_bin = 'testbin/consul_' . $uname . '_' . $arch; |
30
|
4
|
50
|
33
|
|
|
559
|
$consul_bin = '../' . $consul_bin if $ENV{PWD} and $ENV{PWD} =~ /\/t$/; |
31
|
4
|
|
|
|
|
214
|
my @args = ('agent', '-server', '-bootstrap-expect', '1', '-data-dir', $consul_data_dir, '-log-level', 'err'); |
32
|
4
|
|
|
|
|
740
|
print STDERR "##Ignore WARNING: Bootstrap* and [ERR] agent* output from consul daemon\n"; |
33
|
4
|
|
|
|
|
0
|
exec $consul_bin, @args; |
34
|
0
|
|
|
|
|
0
|
exit; |
35
|
|
|
|
|
|
|
} |
36
|
4
|
|
|
|
|
28
|
$consul_daemon_pid = $new_pid; #parent |
37
|
4
|
|
|
|
|
12000638
|
sleep 3; |
38
|
4
|
|
|
|
|
69582
|
my $ret = `ps -p $consul_daemon_pid > /dev/null 2>&1;echo \$?`; |
39
|
4
|
|
|
|
|
100
|
chomp $ret; |
40
|
4
|
50
|
|
|
|
94
|
return 0 unless $ret eq '0'; |
41
|
4
|
|
|
|
|
110
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
END { |
45
|
4
|
50
|
|
4
|
|
19898
|
kill 9, $consul_daemon_pid if $consul_daemon_pid; |
46
|
4
|
|
|
|
|
4009020
|
sleep 1; |
47
|
4
|
|
|
|
|
60597
|
system "rm -rf $consul_data_dir > /dev/null 2>&1"; |
48
|
4
|
|
|
|
|
|
system 'rm -rf /tmp/consul*'; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |