| 1 | package Consul::Simple::Test; | ||||||||||||||||||||||||||||
| 2 | 10 | $Consul::Simple::Test::VERSION = '1.142430'; | |||||||||||||||||||||||||||
| 3 | 10 | my $consul_data_dir = '/tmp/consul_data_' . $$; | |||||||||||||||||||||||||||
| 4 | 10 | our $consul_daemon_pid; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | sub init_tests { | ||||||||||||||||||||||||||
|
Subroutine
init_tests: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 7 | 10 | my $can_test = init_server(); | |||||||||||||||||||||||||||
| 8 | 5 | ▶ | if(not $can_test) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 9 | 0 | print STDERR "#full tests can only be run on Linux or MacOS(Darwin) x86_64. Skipping all.\n"; | |||||||||||||||||||||||||||
| 10 | 0 | exit 0; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 10 | ▶ | sub init_server { | ||||||||||||||||||||||||||
|
Subroutine
init_server: called CC=10 SCAR=25.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 10 | my $uname = `uname 2>&1`; | |||||||||||||||||||||||||||
| 16 | 10 | chomp $uname; | |||||||||||||||||||||||||||
| 17 | 10 | ▶ | if($uname ne 'Linux' and $uname ne 'Darwin') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$uname ne "Linux" and $uname ne "Darwin"
MC/DC0%0/2
$uname ne "Linux" and $uname ne "Darwin"
$uname ne "Linux"
$uname ne "Darwin"
Truth table33%1/3
A and B
A= $uname ne "Linux"B= $uname ne "Darwin"
| |||||||||||||||||||||||||||||
| 18 | 0 | return 0; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 10 | my $arch = `uname -m 2>&1`; | |||||||||||||||||||||||||||
| 21 | 10 | chomp $arch; | |||||||||||||||||||||||||||
| 22 | 10 | ▶ | if($arch ne 'x86_64') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | return 0; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 10 | ▶ | mkdir $consul_data_dir || return 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$consul_data_dir || (return 0)
MC/DC0%0/1
$consul_data_dir || (return 0)
$consul_data_dir
Truth table50%1/2
A
A= $consul_data_dir
| |||||||||||||||||||||||||||||
| 26 | 10 | my $new_pid = fork; | |||||||||||||||||||||||||||
| 27 | 10 | ▶ | return 0 if not defined $new_pid; #fork failed. (!??) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 10 | ▶ | if(not $new_pid) { #child | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 5 | my $consul_bin = 'testbin/consul_' . $uname . '_' . $arch; | |||||||||||||||||||||||||||
| 30 | 5 | ▶ | $consul_bin = '../' . $consul_bin if $ENV{PWD} and $ENV{PWD} =~ /\/t$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"PWD"} and $ENV{"PWD"} =~ m[/t$]
MC/DC0%0/2
$ENV{"PWD"} and $ENV{"PWD"} =~ m[/t$]
$ENV{"PWD"}
$ENV{"PWD"} =~ m[/t$]
Truth table33%1/3
A and B
A= $ENV{"PWD"}B= $ENV{"PWD"} =~ m[/t$]
| |||||||||||||||||||||||||||||
| 31 | 5 | my @args = ('agent', '-server', '-bootstrap-expect', '1', '-data-dir', $consul_data_dir, '-log-level', 'err'); | |||||||||||||||||||||||||||
| 32 | 5 | print STDERR "##Ignore WARNING: Bootstrap* and [ERR] agent* output from consul daemon\n"; | |||||||||||||||||||||||||||
| 33 | 5 | exec $consul_bin, @args; | |||||||||||||||||||||||||||
| 34 | 0 | exit; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 5 | $consul_daemon_pid = $new_pid; #parent | |||||||||||||||||||||||||||
| 37 | 5 | sleep 3; | |||||||||||||||||||||||||||
| 38 | 5 | my $ret = `ps -p $consul_daemon_pid > /dev/null 2>&1;echo \$?`; | |||||||||||||||||||||||||||
| 39 | 5 | chomp $ret; | |||||||||||||||||||||||||||
| 40 | 5 | ▶ | return 0 unless $ret eq '0'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 5 | return 1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 45 | 5 | ▶ | kill 9, $consul_daemon_pid if $consul_daemon_pid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 5 | sleep 1; | |||||||||||||||||||||||||||
| 47 | 5 | system "rm -rf $consul_data_dir > /dev/null 2>&1"; | |||||||||||||||||||||||||||
| 48 | 5 | system 'rm -rf /tmp/consul*'; | |||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 10 | 1; | |||||||||||||||||||||||||||