| 1 | package Test::Consul; | ||||||||||||||||||||||||||||
| 2 | 5 | $Test::Consul::VERSION = '0.017'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Run a consul server for testing | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use File::Which qw(which); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use JSON::MaybeXS qw(JSON encode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use POSIX qw(WNOHANG); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use HTTP::Tiny v0.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Net::EmptyPort qw(check_port can_bind); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use File::Temp qw(tempfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Data::Random qw(rand_words); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Types::Standard qw(Bool Enum Undef); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use Types::Common::Numeric qw(PositiveInt PositiveOrZeroInt); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use Types::Common::String qw(NonEmptySimpleStr); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | my $start_port = 49152; | |||||||||||||||||||||||||||
| 25 | 5 | my $current_port = $start_port; | |||||||||||||||||||||||||||
| 26 | 5 | my $end_port = 65535; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _unique_empty_port { | ||||||||||||||||||||||||||
|
Subroutine
_unique_empty_port: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($udp_too) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | my $port = 0; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | while ($port == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $current_port ++; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | $current_port = $start_port if $current_port > $end_port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | next if check_port($current_port, 'tcp'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | next if ! can_bind('127.0.0.1', $current_port, 'tcp'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | next if $udp_too and check_port($current_port, 'udp'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$udp_too and check_port($current_port, "udp")
MC/DC0%0/2
$udp_too and check_port($current_port, "udp")
$udp_too
check_port($current_port, "udp")
Truth table0%0/3
A and B
A= $udp_tooB= check_port($current_port, "udp")
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | next if $udp_too and (! can_bind('127.0.0.1', $current_port, 'udp')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$udp_too and not can_bind("127.0.0.1", $current_port, "udp")
MC/DC0%0/2
$udp_too and not can_bind("127.0.0.1", $current_port, "udp")
$udp_too
not can_bind("127.0.0.1", $current_port, "udp")
Truth table0%0/3
A and not(B)
A= $udp_tooB= not can_bind("127.0.0.1", $current_port, "udp")
| |||||||||||||||||||||||||||||
| 39 | 0 | $port = $current_port; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # Make sure we return a scalar with just numeric data so it gets | ||||||||||||||||||||||||||||
| 43 | # JSON encoded without quotes. | ||||||||||||||||||||||||||||
| 44 | 0 | return $port; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub _generate_name { | ||||||||||||||||||||||||||
|
Subroutine
_generate_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 0 | my ($wordcount) = @_; | |||||||||||||||||||||||||||
| 49 | 0 | join '-', map { lc } rand_words(size => $wordcount, shuffle => 1); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | has _pid => ( | |||||||||||||||||||||||||||
| 53 | is => 'rw', | ||||||||||||||||||||||||||||
| 54 | predicate => '_has_pid', | ||||||||||||||||||||||||||||
| 55 | clearer => '_clear_pid', | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 5 | has port => ( | |||||||||||||||||||||||||||
| 59 | is => 'lazy', | ||||||||||||||||||||||||||||
| 60 | isa => PositiveInt, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _build_port { | ||||||||||||||||||||||||||
|
Subroutine
_build_port: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 0 | return _unique_empty_port(); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | has serf_lan_port => ( | |||||||||||||||||||||||||||
| 67 | is => 'lazy', | ||||||||||||||||||||||||||||
| 68 | isa => PositiveInt, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub _build_serf_lan_port { | ||||||||||||||||||||||||||
|
Subroutine
_build_serf_lan_port: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 0 | return _unique_empty_port(1); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 5 | has serf_wan_port => ( | |||||||||||||||||||||||||||
| 75 | is => 'lazy', | ||||||||||||||||||||||||||||
| 76 | isa => PositiveInt, | ||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _build_serf_wan_port { | ||||||||||||||||||||||||||
|
Subroutine
_build_serf_wan_port: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | 0 | return _unique_empty_port(1); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 5 | has server_port => ( | |||||||||||||||||||||||||||
| 83 | is => 'lazy', | ||||||||||||||||||||||||||||
| 84 | isa => PositiveInt, | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _build_server_port { | ||||||||||||||||||||||||||
|
Subroutine
_build_server_port: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | 0 | return _unique_empty_port(); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 5 | has node_name => ( | |||||||||||||||||||||||||||
| 91 | is => 'lazy', | ||||||||||||||||||||||||||||
| 92 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _build_node_name { | ||||||||||||||||||||||||||
|
Subroutine
_build_node_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 95 | 0 | _generate_name(2) | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | has datacenter => ( | |||||||||||||||||||||||||||
| 99 | is => 'lazy', | ||||||||||||||||||||||||||||
| 100 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub _build_datacenter { | ||||||||||||||||||||||||||
|
Subroutine
_build_datacenter: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 103 | 0 | _generate_name(1) | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 5 | has enable_acls => ( | |||||||||||||||||||||||||||
| 107 | is => 'ro', | ||||||||||||||||||||||||||||
| 108 | isa => Bool, | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 5 | has acl_default_policy => ( | |||||||||||||||||||||||||||
| 112 | is => 'ro', | ||||||||||||||||||||||||||||
| 113 | isa => Enum[qw(allow deny)], | ||||||||||||||||||||||||||||
| 114 | default => 'allow', | ||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 5 | has acl_master_token => ( | |||||||||||||||||||||||||||
| 118 | is => 'ro', | ||||||||||||||||||||||||||||
| 119 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 120 | default => '01234567-89AB-CDEF-GHIJ-KLMNOPQRSTUV', | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 5 | has enable_remote_exec => ( | |||||||||||||||||||||||||||
| 124 | is => 'ro', | ||||||||||||||||||||||||||||
| 125 | isa => Bool, | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 5 | has bin => ( | |||||||||||||||||||||||||||
| 129 | is => 'lazy', | ||||||||||||||||||||||||||||
| 130 | isa => NonEmptySimpleStr | Undef, | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub _build_bin { | ||||||||||||||||||||||||||
|
Subroutine
_build_bin: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 133 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 134 | 0 | return $self->found_bin; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 5 | has datadir => ( | |||||||||||||||||||||||||||
| 138 | is => 'ro', | ||||||||||||||||||||||||||||
| 139 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 140 | predicate => 1, | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | has version => ( | ||||||||||||||||||||||||||||
| 144 | is => 'lazy', | ||||||||||||||||||||||||||||
| 145 | isa => PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 147 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 148 | 0 | return $self->found_version; | |||||||||||||||||||||||||||
| 149 | }, | ||||||||||||||||||||||||||||
| 150 | 5 | ); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub running { | ||||||||||||||||||||||||||
|
Subroutine
running: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 154 | 0 | return !!$self->_has_pid(); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub start { | ||||||||||||||||||||||||||
|
Subroutine
start: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 159 | 0 | my $is_class_method = 0; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if (!blessed $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | $self = $self->new(@_); | |||||||||||||||||||||||||||
| 163 | 0 | $is_class_method = 1; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | my $bin = $self->bin(); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # Make sure we have at least Consul 0.6.1 which supports the -dev option. | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | unless ($self->version >= 6_001) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | croak "consul not version 0.6.1 or newer"; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | my @opts; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | my %config = ( | |||||||||||||||||||||||||||
| 176 | node_name => $self->node_name(), | ||||||||||||||||||||||||||||
| 177 | datacenter => $self->datacenter(), | ||||||||||||||||||||||||||||
| 178 | bind_addr => '127.0.0.1', | ||||||||||||||||||||||||||||
| 179 | ports => { | ||||||||||||||||||||||||||||
| 180 | dns => -1, | ||||||||||||||||||||||||||||
| 181 | http => $self->port() + 0, | ||||||||||||||||||||||||||||
| 182 | https => -1, | ||||||||||||||||||||||||||||
| 183 | serf_lan => $self->serf_lan_port() + 0, | ||||||||||||||||||||||||||||
| 184 | serf_wan => $self->serf_wan_port() + 0, | ||||||||||||||||||||||||||||
| 185 | server => $self->server_port() + 0, | ||||||||||||||||||||||||||||
| 186 | }, | ||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | # Version 0.7.0 reduced default performance behaviors in a way | ||||||||||||||||||||||||||||
| 190 | # that makese these tests slower to startup. Override this and | ||||||||||||||||||||||||||||
| 191 | # make leadership election happen ASAP. | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($self->version >= 7_000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | $config{performance} = { raft_multiplier => 1 }; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # gRPC health checks were added 1.0.5, and in dev mode are enabled and bind | ||||||||||||||||||||||||||||
| 197 | # to port 8502, which then clashes if you want to run up a second | ||||||||||||||||||||||||||||
| 198 | # Test::Consul. Just disable it. | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ($self->version >= 1_000_005) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | $config{ports}{grpc} = -1; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | # Likewise for grpc above, 1.14.0 added grpc_tls which listens on 8503, and | ||||||||||||||||||||||||||||
| 204 | # would clash with a second active Test::Consul | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ($self->version >= 1_014_000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | $config{ports}{grpc_tls} = -1; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ($self->enable_acls()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($self->version >= 1_004_000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 0 | croak "ACLs not supported with Consul >= 1.4.0" | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | $config{acl_master_token} = $self->acl_master_token(); | |||||||||||||||||||||||||||
| 215 | 0 | $config{acl_default_policy} = $self->acl_default_policy(); | |||||||||||||||||||||||||||
| 216 | 0 | $config{acl_datacenter} = $self->datacenter(); | |||||||||||||||||||||||||||
| 217 | 0 | $config{acl_token} = $self->acl_master_token(); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if (defined $self->enable_remote_exec) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $config{disable_remote_exec} = $self->enable_remote_exec ? JSON->false : JSON->true; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | my $configpath; | |||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ($self->has_datadir()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | $config{data_dir} = $self->datadir(); | |||||||||||||||||||||||||||
| 227 | 0 | $config{bootstrap} = \1; | |||||||||||||||||||||||||||
| 228 | 0 | $config{server} = \1; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | my $datapath = path($self->datadir()); | |||||||||||||||||||||||||||
| 231 | 0 | $datapath->remove_tree; | |||||||||||||||||||||||||||
| 232 | 0 | $datapath->mkpath; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | $configpath = $datapath->child("consul.json"); | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||
| 237 | 0 | push @opts, '-dev'; | |||||||||||||||||||||||||||
| 238 | 0 | $configpath = path((tempfile(SUFFIX => '.json'))[1]); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 0 | $configpath->spew(encode_json(\%config)); | |||||||||||||||||||||||||||
| 242 | 0 | push @opts, '-config-file', "$configpath"; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | my $pid = fork(); | |||||||||||||||||||||||||||
| 245 | 0 | ▶ | unless (defined $pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | croak "fork failed: $!"; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 0 | ▶ | unless ($pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 0 | exec $bin, "agent", @opts; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | my $http = HTTP::Tiny->new(timeout => 10); | |||||||||||||||||||||||||||
| 253 | 0 | my $now = time; | |||||||||||||||||||||||||||
| 254 | 0 | my $res; | |||||||||||||||||||||||||||
| 255 | 0 | my $port = $self->port(); | |||||||||||||||||||||||||||
| 256 | 0 | ▶ | while (time < $now+30) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 0 | $res = $http->get("http://127.0.0.1:$port/v1/status/leader"); | |||||||||||||||||||||||||||
| 258 | 0 | ▶ | last if $res->{success} && $res->{content} =~ m/^"[0-9\.]+:[0-9]+"$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res->{"success"} and $res->{"content"} =~ /^"[0-9\.]+:[0-9]+"$/
MC/DC0%0/2
$res->{"success"} and $res->{"content"} =~ /^"[0-9\.]+:[0-9]+"$/
$res->{"success"}
$res->{"content"} =~ /^"[0-9\.]+:[0-9]+"$/
Truth table0%0/3
A and B
A= $res->{"success"}B= $res->{"content"} =~ /^"[0-9\.]+:[0-9]+"$/
| |||||||||||||||||||||||||||||
| 259 | 0 | sleep 1; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | 0 | ▶ | unless ($res->{success}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | kill 'KILL', $pid; | |||||||||||||||||||||||||||
| 263 | 0 | croak "consul API test failed: $res->{status} $res->{reason}"; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | ▶ | unlink $configpath if !$self->has_datadir(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | $self->_pid($pid); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | return $self if $is_class_method; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 0 | return; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | sub stop { | ||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 275 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 276 | 0 | ▶ | return unless $self->_has_pid(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | my $pid = $self->_pid(); | |||||||||||||||||||||||||||
| 278 | 0 | $self->_clear_pid(); | |||||||||||||||||||||||||||
| 279 | 0 | kill 'TERM', $pid; | |||||||||||||||||||||||||||
| 280 | 0 | my $now = time; | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | while (time < $now+2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 0 | ▶ | return if waitpid($pid, WNOHANG) > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | 0 | kill 'KILL', $pid; | |||||||||||||||||||||||||||
| 285 | 0 | return; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | sub end { | ||||||||||||||||||||||||||
|
Subroutine
end: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 289 | 0 | goto \&stop; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 293 | 0 | goto \&stop; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub join { | ||||||||||||||||||||||||||
|
Subroutine
join: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 297 | 0 | my ($self, $other) = @_; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | my $http = HTTP::Tiny->new(timeout => 10); | |||||||||||||||||||||||||||
| 300 | 0 | my $port = $self->port; | |||||||||||||||||||||||||||
| 301 | 0 | my $other_lan_port = $other->serf_lan_port; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | my $res = $http->put("http://127.0.0.1:$port/v1/agent/join/127.0.0.1:$other_lan_port"); | |||||||||||||||||||||||||||
| 304 | 0 | ▶ | unless ($res->{success}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | 0 | croak "join failed: $res->{status} $res->{reason}" | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub wan_join { | ||||||||||||||||||||||||||
|
Subroutine
wan_join: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 310 | 0 | my ($self, $other) = @_; | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 0 | my $http = HTTP::Tiny->new(timeout => 10); | |||||||||||||||||||||||||||
| 313 | 0 | my $port = $self->port; | |||||||||||||||||||||||||||
| 314 | 0 | my $other_wan_port = $other->serf_wan_port; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | my $res = $http->put("http://127.0.0.1:$port/v1/agent/join/127.0.0.1:$other_wan_port?wan=1"); | |||||||||||||||||||||||||||
| 317 | 0 | ▶ | unless ($res->{success}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | croak "WAN join failed: $res->{status} $res->{reason}" | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 4 | ▶ | sub found_bin { | ||||||||||||||||||||||||||
|
Subroutine
found_bin: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||
| 323 | 4 | state ($bin, $bin_searched_for); | |||||||||||||||||||||||||||
| 324 | 4 | ▶ | return $bin if $bin_searched_for; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 4 | ▶ | my $binpath = $ENV{CONSUL_BIN} || which "consul"; | ||||||||||||||||||||||||||
|
Condition33%1/3
$ENV{'CONSUL_BIN'} || which('consul')
MC/DC0%0/2
$ENV{'CONSUL_BIN'} || which('consul')
$ENV{'CONSUL_BIN'}
which('consul')
Truth table33%1/3
A || B
A= $ENV{'CONSUL_BIN'}B= which('consul')
| |||||||||||||||||||||||||||||
| 326 | 4 | ▶ | $bin = $binpath if defined($binpath) && -x $binpath; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $binpath and -x $binpath
MC/DC0%0/2
defined $binpath and -x $binpath
defined $binpath
-x $binpath
Truth table33%1/3
A and B
A= defined $binpathB= -x $binpath
| |||||||||||||||||||||||||||||
| 327 | 4 | $bin_searched_for = 1; | |||||||||||||||||||||||||||
| 328 | 4 | return $bin; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 4 | ▶ | sub skip_all_if_no_bin { | ||||||||||||||||||||||||||
|
Subroutine
skip_all_if_no_bin: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 332 | 4 | my ($class) = @_; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 4 | ▶ | croak 'The skip_all_if_no_bin method may only be used if the plan ' . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 'function is callable on the main package (which Test::More ' . | ||||||||||||||||||||||||||||
| 336 | 'and Test2::Tools::Basic provide)' | ||||||||||||||||||||||||||||
| 337 | if !main->can('plan'); | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 4 | ▶ | return if defined $class->found_bin(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 4 | main::plan(skip_all => 'The Consul binary must be available to run this test.'); | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub found_version { | ||||||||||||||||||||||||||
|
Subroutine
found_version: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 345 | 0 | state ($version); | |||||||||||||||||||||||||||
| 346 | 0 | ▶ | return $version if defined $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | 0 | my $bin = found_bin(); | |||||||||||||||||||||||||||
| 348 | 0 | ($version) = qx{$bin version}; | |||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ($version and $version =~ m{v(\d+)\.(\d+)\.(\d+)}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$version and $version =~ /v(\d+)\.(\d+)\.(\d+)/
MC/DC0%0/2
$version and $version =~ /v(\d+)\.(\d+)\.(\d+)/
$version
$version =~ /v(\d+)\.(\d+)\.(\d+)/
Truth table0%0/3
A and B
A= $versionB= $version =~ /v(\d+)\.(\d+)\.(\d+)/
| |||||||||||||||||||||||||||||
| 350 | 0 | $version = sprintf('%03d%03d%03d', $1, $2, $3); | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | else { | ||||||||||||||||||||||||||||
| 353 | 0 | $version = 0; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub skip_all_unless_version { | ||||||||||||||||||||||||||
|
Subroutine
skip_all_unless_version: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 358 | 0 | my ($class, $minver, $maxver) = @_; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | ▶ | croak 'usage: Test::Consul->skip_all_unless_version($minver, [$maxver])' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | unless defined $minver; | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | ▶ | croak 'The skip_all_unless_version method may only be used if the plan ' . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 'function is callable on the main package (which Test::More ' . | ||||||||||||||||||||||||||||
| 365 | 'and Test2::Tools::Basic provide)' | ||||||||||||||||||||||||||||
| 366 | if !main->can('plan'); | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 0 | $class->skip_all_if_no_bin; | |||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 0 | my $version = $class->found_version; | |||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if (defined $maxver) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | return if $minver <= $version && $maxver > $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$minver <= $version and $maxver > $version
MC/DC0%0/2
$minver <= $version and $maxver > $version
$minver <= $version
$maxver > $version
Truth table0%0/3
A and B
A= $minver <= $versionB= $maxver > $version
| |||||||||||||||||||||||||||||
| 374 | 0 | main::plan(skip_all => "Consul must be between version $minver and $maxver to run this test."); | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | else { | ||||||||||||||||||||||||||||
| 377 | 0 | ▶ | return if $minver <= $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | main::plan(skip_all => "Consul must be version $minver or higher to run this test."); | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 5 | 1; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =pod | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | =for markdown [](http://travis-ci.org/robn/Test-Consul) | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =head1 NAME | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | Test::Consul - Run a Consul server for testing | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | use Test::Consul; | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | # succeeds or dies | ||||||||||||||||||||||||||||
| 399 | my $tc = Test::Consul->start; | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | my $consul_baseurl = "http://127.0.0.1:".$tc->port; | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | # do things with Consul here | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | # kill test server (or let $tc fall out of scope, destructor will clean up) | ||||||||||||||||||||||||||||
| 406 | $tc->end; | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | This module starts and stops a standalone Consul instance. It's designed to be | ||||||||||||||||||||||||||||
| 411 | used to help test Consul-aware Perl programs. | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | It's assumed that you have Consul 0.6.4 installed somewhere. | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | =head1 ARGUMENTS | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | =head2 port | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | The TCP port for HTTP API endpoint. Consul's default is C<8500>, but | ||||||||||||||||||||||||||||
| 420 | this defaults to a random unused port. | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | =head2 serf_lan_port | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | The TCP and UDP port for the Serf LAN. Consul's default is C<8301>, but | ||||||||||||||||||||||||||||
| 425 | this defaults to a random unused port. | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =head2 serf_wan_port | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | The TCP and UDP port for the Serf WAN. Consul's default is C<8302>, but | ||||||||||||||||||||||||||||
| 430 | this defaults to a random unused port. | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =head2 server_port | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | The TCP port for the RPC Server address. Consul's default is C<8300>, but | ||||||||||||||||||||||||||||
| 435 | this defaults to a random unused port. | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | =head2 node_name | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | The name of this node. If not provided, one will be generated. | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head2 datacenter | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | The name of the datacenter. If not provided, one will be generated. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | =head2 enable_acls | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | Set this to true to enable ACLs. Note that Consul ACLs changed substantially in | ||||||||||||||||||||||||||||
| 448 | Consul 1.4, and L<Test::Consul> has not yet been updated to support them. If | ||||||||||||||||||||||||||||
| 449 | you try to enable them with Consul 1.4+, L<Test::Consul> will croak. See | ||||||||||||||||||||||||||||
| 450 | L<https://github.com/robn/Test-Consul/issues/7> for more info. | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | =head2 acl_default_policy | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | Set this to either C<allow> or C<deny>. The default is C<allow>. | ||||||||||||||||||||||||||||
| 455 | See L<https://www.consul.io/docs/agent/options.html#acl_default_policy> for more | ||||||||||||||||||||||||||||
| 456 | information. | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | =head2 acl_master_token | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | If L</enable_acls> is true then this token will be used as the master | ||||||||||||||||||||||||||||
| 461 | token. By default this will be C<01234567-89AB-CDEF-GHIJ-KLMNOPQRSTUV>. | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | =head2 enable_acls | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | Set this to true to enable remote execution (off by default since Consul 0.8.0) | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | =head2 bin | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | Location of the C<consul> binary. If not provided then the binary will | ||||||||||||||||||||||||||||
| 470 | be retrieved from L</found_bin>. | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | =head2 datadir | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | Directory for Consul's data store. If not provided, the C<-dev> option is used | ||||||||||||||||||||||||||||
| 475 | and no datadir is used. | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | =head2 running | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | Returns C<true> if L</start> has been called and L</stop> has not been called. | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | =head1 METHODS | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =head2 start | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | # As an object method: | ||||||||||||||||||||||||||||
| 488 | my $tc = Test::Consul->new(%args); | ||||||||||||||||||||||||||||
| 489 | $tc->start(); | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | # As a class method: | ||||||||||||||||||||||||||||
| 492 | my $tc = Test::Consul->start(%args); | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | Starts a Consul instance. This method can take a moment to run, because it | ||||||||||||||||||||||||||||
| 495 | waits until Consul's HTTP endpoint is available before returning. If it fails | ||||||||||||||||||||||||||||
| 496 | for any reason an exception is thrown. In this way you can be sure that Consul | ||||||||||||||||||||||||||||
| 497 | is ready for service if this method returns successfully. | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | =head2 stop | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | $tc->stop(); | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | Kill the Consul instance. Graceful shutdown is attempted first, and if it | ||||||||||||||||||||||||||||
| 504 | doesn't die within a couple of seconds, the process is killed. | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | This method is also called if the instance of this class falls out of scope. | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | =head2 join | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | my $tc1 = Test::Consul->start; | ||||||||||||||||||||||||||||
| 511 | my $tc2 = Test::Consul->start(datacenter => $tc1); | ||||||||||||||||||||||||||||
| 512 | $tc1->wan_join($tc2); | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | Perform a join to another L<Test::Consul> instance. Use this to test Consul applications that operate across nodes. | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | =head2 wan_join | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | my $tc1 = Test::Consul->start; | ||||||||||||||||||||||||||||
| 519 | my $tc2 = Test::Consul->start; | ||||||||||||||||||||||||||||
| 520 | $tc1->wan_join($tc2); | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | Perform a WAN join to another L<Test::Consul> instance. Use this to test Consul | ||||||||||||||||||||||||||||
| 523 | applications that operate across datacenters. | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | See also L</start> which acts as both a class and instance method. | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | =head2 found_bin | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | Return the value of the C<CONSUL_BIN> env var, if set, or uses L<File::Which> | ||||||||||||||||||||||||||||
| 532 | to search the system for an installed binary. Returns C<undef> if no consul | ||||||||||||||||||||||||||||
| 533 | binary could be found. | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | =head2 skip_all_if_no_bin | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | Test::Consul->skip_all_if_no_bin; | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | This class method issues a C<skip_all> on the main package if the | ||||||||||||||||||||||||||||
| 540 | consul binary could not be found (L</found_bin> returns false). | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | =head2 found_version | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | Return the version of the consul binary, by running the binary return by | ||||||||||||||||||||||||||||
| 545 | L</found_bin> with the C<version> argument. Returns 0 if the version can't be | ||||||||||||||||||||||||||||
| 546 | determined. | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | =head2 skip_all_unless_version | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | Test::Consul->skip_all_unless_version($minver, [$maxver]); | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | This class method issues a C<skip_all> on the main package if the consul binary | ||||||||||||||||||||||||||||
| 553 | is not between C<$minver> and C<$maxvar> (exclusive). | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | =over 4 | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | =item * | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | L<Consul> - Consul client library. Uses L<Test::Consul> in its test suite. | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | =back | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | =head2 Bugs / Feature Requests | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | Please report any bugs or feature requests through the issue tracker | ||||||||||||||||||||||||||||
| 570 | at L<https://github.com/robn/Test-Consul/issues>. | ||||||||||||||||||||||||||||
| 571 | You will be notified automatically of any progress on your issue. | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | =head2 Source Code | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | This is open source software. The code repository is available for | ||||||||||||||||||||||||||||
| 576 | public review and contribution under the terms of the license. | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | L<https://github.com/robn/Test-Consul> | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | git clone https://github.com/robn/Test-Consul.git | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | =over 4 | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | =item * | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | Rob Norris <robn@despairlabs.com> | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | =back | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | =head1 CONTRIBUTORS | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | =over 4 | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | =item * | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | Aran Deltac <bluefeet@gmail.com> | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | =item * | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | Matthew Horsfall <wolfsage@gmail.com> | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | =back | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | This software is copyright (c) 2015 by Rob N ★ and was supported by FastMail | ||||||||||||||||||||||||||||
| 609 | Pty Ltd. | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 612 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | =cut | ||||||||||||||||||||||||||||