File Coverage

blib/lib/Testcontainers/Wait/Multi.pm
Criterion Covered Total %
statement 15 26 57.6
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 35 57.1


line stmt bran cond sub pod time code
1             package Testcontainers::Wait::Multi;
2             # ABSTRACT: Composite wait strategy combining multiple strategies
3              
4 4     4   29 use strict;
  4         8  
  4         152  
5 4     4   20 use warnings;
  4         6  
  4         221  
6 4     4   22 use Moo;
  4         24  
  4         28  
7 4     4   1684 use Carp qw( croak );
  4         24  
  4         342  
8 4     4   25 use Log::Any qw( $log );
  4         10  
  4         24  
9              
10             our $VERSION = '0.001';
11              
12             with 'Testcontainers::Wait::Base';
13              
14             =head1 SYNOPSIS
15              
16             use Testcontainers::Wait;
17              
18             my $wait = Testcontainers::Wait::for_all(
19             Testcontainers::Wait::for_listening_port('5432/tcp'),
20             Testcontainers::Wait::for_log('ready to accept connections'),
21             );
22              
23             =head1 DESCRIPTION
24              
25             Combines multiple wait strategies. All strategies must pass for the
26             container to be considered ready. Equivalent to Go's C.
27              
28             =cut
29              
30             has strategies => (
31             is => 'ro',
32             required => 1,
33             );
34              
35             =attr strategies
36              
37             ArrayRef of wait strategy objects. All must pass.
38              
39             =cut
40              
41             sub check {
42 0     0 0   my ($self, $container) = @_;
43              
44 0           for my $strategy (@{$self->strategies}) {
  0            
45 0           my $ready = eval { $strategy->check($container) };
  0            
46 0 0         unless ($ready) {
47 0           $log->tracef("Multi strategy: %s not ready", ref $strategy);
48 0           return 0;
49             }
50             }
51              
52 0           $log->debugf("All %d strategies passed", scalar @{$self->strategies});
  0            
53 0           return 1;
54             }
55              
56             =method check($container)
57              
58             All child strategies must return true for this to return true.
59              
60             =cut
61              
62             1;