| 1 | package Tapper::Cmd::Testrun; | ||||||||||||||||||||||||||||||||
| 2 | 6 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||||||
| 3 | 6 | $Tapper::Cmd::Testrun::VERSION = '5.0.14'; | |||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Tapper::Model 'model'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Perl6::Junction qw/any/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Hash::Merge::Simple qw/merge/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use parent 'Tapper::Cmd'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Tapper::Cmd::Requested; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Tapper::Cmd::Precondition; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Tapper::Cmd::Notification; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | sub find_matching_hosts | ||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
find_matching_hosts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 20 | 5 | return; | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | sub create | ||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=12 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 27 | 5 | my ($self, $plan, $instance) = @_; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | if ( not ref($plan) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | 0 | require YAML::Syck; | |||||||||||||||||||||||||||||||
| 31 | 0 | $plan = YAML::Syck::Load($plan); | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | if ( not ref($plan) eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | 0 | die "'$plan' is not YAML containing a testrun description\n"; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | # pass testplan context down to preconditions, | ||||||||||||||||||||||||||||||||
| 39 | # merged into their potentially own context | ||||||||||||||||||||||||||||||||
| 40 | my @plan_preconditions = map { | ||||||||||||||||||||||||||||||||
| 41 | $_->{context} = merge($_->{context}, $plan->{context}) | ||||||||||||||||||||||||||||||||
| 42 | 18 | ▶ | if $_->{precondition_type} eq 'testprogram'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 18 | $_; | |||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | } @{$plan->{preconditions} // []}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$plan->{"preconditions"} // []
MC/DC0%0/1
$plan->{"preconditions"} // []
$plan->{"preconditions"}
Truth table50%1/2
A
A= $plan->{"preconditions"}
| |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 5 | my @preconditions = Tapper::Cmd::Precondition | |||||||||||||||||||||||||||||||
| 47 | ->new({ schema => $self->schema }) | ||||||||||||||||||||||||||||||||
| 48 | ->add(\@plan_preconditions) | ||||||||||||||||||||||||||||||||
| 49 | ; | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 5 | ▶ | my %args = map { lc($_) => $plan->{$_} } grep { lc($_) ne 'preconditions' and $_ !~ /^requested_(hosts|features)/i } keys %$plan; | ||||||||||||||||||||||||||||||
|
Condition100%3/3
lc $_ ne 'preconditions' && !($_ =~ /^requested_(hosts|features)/i)
MC/DC100%2/2
lc $_ ne 'preconditions' && !($_ =~ /^requested_(hosts|features)/i)
lc $_ ne 'preconditions'
!($_ =~ /^requested_(hosts|features)/i)
Truth table100%3/3
A && not(B)
A= lc $_ ne 'preconditions'B= !($_ =~ /^requested_(hosts|features)/i)
| |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 5 | my @testruns; | |||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | foreach my $host (@{$plan->{requested_hosts_all} || [] }) { | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$plan->{'requested_hosts_all'} || []
MC/DC0%0/1
$plan->{'requested_hosts_all'} || []
$plan->{'requested_hosts_all'}
Truth table50%1/2
A
A= $plan->{'requested_hosts_all'}
| |||||||||||||||||||||||||||||||||
| 55 | 7 | my $merged_arguments = merge \%args, {precondition => \@plan_preconditions, | |||||||||||||||||||||||||||||||
| 56 | requested_hosts => $host, | ||||||||||||||||||||||||||||||||
| 57 | testplan_id => $instance, | ||||||||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||||||
| 59 | 7 | my $testrun_id = $self->add($merged_arguments); | |||||||||||||||||||||||||||||||
| 60 | 7 | $self->assign_preconditions($testrun_id, @preconditions); | |||||||||||||||||||||||||||||||
| 61 | 7 | push @testruns, $testrun_id; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | if ($plan->{requested_hosts_any}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | my $merged_arguments = merge \%args, {precondition => \@plan_preconditions, | ||||||||||||||||||||||||||||||||
| 65 | requested_hosts => $plan->{requested_hosts_any}, | ||||||||||||||||||||||||||||||||
| 66 | 2 | testplan_id => $instance}; | |||||||||||||||||||||||||||||||
| 67 | 2 | my $testrun_id = $self->add($merged_arguments ); | |||||||||||||||||||||||||||||||
| 68 | 2 | $self->assign_preconditions($testrun_id, @preconditions); | |||||||||||||||||||||||||||||||
| 69 | 2 | push @testruns, $testrun_id; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | 5 | foreach my $host ($self->find_matching_hosts($plan->{requested_features_all})) { | |||||||||||||||||||||||||||||||
| 72 | 0 | my $merged_arguments = merge \%args, {precondition => \@plan_preconditions, | |||||||||||||||||||||||||||||||
| 73 | requested_hosts => $host, | ||||||||||||||||||||||||||||||||
| 74 | testplan_id => $instance}; | ||||||||||||||||||||||||||||||||
| 75 | 0 | my $testrun_id = $self->add($merged_arguments ); | |||||||||||||||||||||||||||||||
| 76 | 0 | $self->assign_preconditions($testrun_id, @preconditions); | |||||||||||||||||||||||||||||||
| 77 | 0 | push @testruns, $testrun_id; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | 5 | ▶ | if ($plan->{requested_features_any}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | my $merged_arguments = merge \%args, {precondition => \@plan_preconditions, | ||||||||||||||||||||||||||||||||
| 81 | requested_features => $plan->{requested_features_any}, | ||||||||||||||||||||||||||||||||
| 82 | 2 | testplan_id => $instance}; | |||||||||||||||||||||||||||||||
| 83 | 2 | my $testrun_id = $self->add($merged_arguments ); | |||||||||||||||||||||||||||||||
| 84 | 2 | $self->assign_preconditions($testrun_id, @preconditions); | |||||||||||||||||||||||||||||||
| 85 | 2 | push @testruns, $testrun_id; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | 5 | ▶ | if ( not grep { $_ =~ /^requested_(hosts|features)/i } keys %$plan) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | 0 | my $merged_arguments = merge \%args, {precondition => \@plan_preconditions, | |||||||||||||||||||||||||||||||
| 89 | testplan_id => $instance, | ||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||
| 91 | 0 | my $testrun_id = $self->add($merged_arguments); | |||||||||||||||||||||||||||||||
| 92 | 0 | $self->assign_preconditions($testrun_id, @preconditions); | |||||||||||||||||||||||||||||||
| 93 | 0 | push @testruns, $testrun_id; | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 5 | return @testruns; | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 12 | ▶ | sub add { | ||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 12 | my ($self, $received_args) = @_; | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 12 | ▶ | my %args = %{$received_args || {}}; # copy | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$received_args || {}
MC/DC0%0/1
$received_args || {}
$received_args
Truth table50%1/2
A
A= $received_args
| |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 12 | ▶ | $args{notes} ||= ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"notes"} ||= ""
MC/DC100%1/1
$args{"notes"} ||= ""
$args{"notes"}
Truth table100%2/2
A
A= $args{"notes"}
| |||||||||||||||||||||||||||||||||
| 110 | 12 | ▶ | $args{shortname} ||= ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"shortname"} ||= ""
MC/DC100%1/1
$args{"shortname"} ||= ""
$args{"shortname"}
Truth table100%2/2
A
A= $args{"shortname"}
| |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 12 | my ( $testrun_id, $exception ); | |||||||||||||||||||||||||||||||
| 113 | 12 | my $or_schema = $self->schema; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 12 | ▶ | try { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||
| 116 | 12 | ▶ | $or_schema->txn_do(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=25 SCAR=36.9
| |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 12 | ▶ | $args{topic_name} = $args{topic} || 'Misc'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'topic'} || 'Misc'
MC/DC100%1/1
$args{'topic'} || 'Misc'
$args{'topic'}
Truth table100%2/2
A
A= $args{'topic'}
| |||||||||||||||||||||||||||||||||
| 119 | 12 | my $topic = $or_schema->resultset('Topic')->find_or_create({name => $args{topic_name}}); | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 12 | ▶ | $args{earliest} ||= DateTime->now; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"earliest"} ||= "DateTime"->now
MC/DC0%0/2
$args{"earliest"} ||= "DateTime"->now
$args{"earliest"}
"DateTime"->now
Truth table66%2/3
A ||= B
A= $args{"earliest"}B= "DateTime"->now
| |||||||||||||||||||||||||||||||||
| 122 | 12 | ▶ | $args{owner} ||= $ENV{USER} || 'nobody'; | ||||||||||||||||||||||||||||||
|
Condition60%3/5
$args{"owner"} ||= $ENV{"USER"} || "nobody"
$ENV{'USER'} || 'nobody'
MC/DC0%0/2
$args{"owner"} ||= $ENV{"USER"} || "nobody"
$args{"owner"}
$ENV{'USER'}
Truth table33%1/3
A ||= B
A= $args{"owner"}B= $ENV{'USER'}
| |||||||||||||||||||||||||||||||||
| 123 | 12 | ▶ | $args{owner_id} ||= Tapper::Model::get_or_create_owner( $args{owner} ); | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"owner_id"} ||= Tapper::Model::get_or_create_owner($args{"owner"})
MC/DC0%0/2
$args{"owner_id"} ||= Tapper::Model::get_or_create_owner($args{"owner"})
$args{"owner_id"}
Tapper::Model::get_or_create_owner($args{"owner"})
Truth table33%1/3
A ||= B
A= $args{"owner_id"}B= Tapper::Model::get_or_create_owner($args{"owner"})
| |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 12 | ▶ | if ($args{requested_hosts} and not $args{requested_host_ids}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"requested_hosts"} and not $args{"requested_host_ids"}
MC/DC50%1/2
$args{"requested_hosts"} and not $args{"requested_host_ids"}
$args{"requested_hosts"}
not $args{"requested_host_ids"}
Truth table66%2/3
A and not(B)
A= $args{"requested_hosts"}B= not $args{"requested_host_ids"}
| |||||||||||||||||||||||||||||||||
| 126 | 10 | ▶ | foreach my $host (@{ref $args{requested_hosts} eq 'ARRAY' ? $args{requested_hosts} : [ $args{requested_hosts} ]}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 127 | 13 | my $host_result = $or_schema->resultset('Host')->search({name => $host}, {rows => 1})->first; | |||||||||||||||||||||||||||||||
| 128 | 13 | ▶ | die "Can not request host '$host'. This host is not known to tapper\n" if not $host_result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 13 | ▶ | push @{$args{requested_host_ids}}, $host_result->id if $host_result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 12 | ▶ | if ( not $args{queue_id} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 12 | ▶ | $args{queue} ||= 'AdHoc'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"queue"} ||= "AdHoc"
MC/DC100%1/1
$args{"queue"} ||= "AdHoc"
$args{"queue"}
Truth table100%2/2
A
A= $args{"queue"}
| |||||||||||||||||||||||||||||||||
| 135 | 12 | my $queue_result = $or_schema->resultset('Queue')->search({name => $args{queue}}); | |||||||||||||||||||||||||||||||
| 136 | 12 | ▶ | die qq{Queue "$args{queue}" does not exists\n} if not $queue_result->count; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 12 | $args{queue_id} = $queue_result->search({}, {rows => 1})->first->id; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 12 | $testrun_id = $or_schema->resultset('Testrun')->add(\%args); | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 12 | ▶ | if ( $args{requested_features} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 2 | foreach my $feature ( | |||||||||||||||||||||||||||||||
| 144 | @{ | ||||||||||||||||||||||||||||||||
| 145 | ref $args{requested_features} eq 'ARRAY' | ||||||||||||||||||||||||||||||||
| 146 | ? $args{requested_features} | ||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | : [ $args{requested_features} ] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||
| 149 | ) { | ||||||||||||||||||||||||||||||||
| 150 | 3 | $or_schema | |||||||||||||||||||||||||||||||
| 151 | ->resultset('TestrunRequestedFeature') | ||||||||||||||||||||||||||||||||
| 152 | ->new({testrun_id => $testrun_id, feature => $feature}) | ||||||||||||||||||||||||||||||||
| 153 | ->insert() | ||||||||||||||||||||||||||||||||
| 154 | ; | ||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 12 | ▶ | if ( $args{requested_resources} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | 0 | my $testrun = $or_schema->resultset('Testrun')->find($testrun_id); | |||||||||||||||||||||||||||||||
| 160 | 0 | foreach my $request (@{$args{requested_resources}}) { | |||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $testrun->add_requested_resource_by_name( ref($request) eq "ARRAY" ? @$request : ($request) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 12 | ▶ | if ( exists $args{notify} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | my $s_notify = $args{notify} // q##; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"notify"} // ""
MC/DC0%0/1
$args{"notify"} // ""
$args{"notify"}
Truth table50%1/2
A
A= $args{"notify"}
| |||||||||||||||||||||||||||||||||
| 167 | 1 | my $notify = Tapper::Cmd::Notification->new(); | |||||||||||||||||||||||||||||||
| 168 | 1 | my $filter = "testrun('id') == $testrun_id"; | |||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | if (lc $args{notify} eq any('pass', 'ok','success')) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 170 | 1 | $filter .= " and testrun('success_word') eq 'pass'"; | |||||||||||||||||||||||||||||||
| 171 | } elsif (lc $args{notify} eq any('fail', 'not_ok','error')) { | ||||||||||||||||||||||||||||||||
| 172 | 0 | $filter .= " and testrun('success_word') eq 'fail'"; | |||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | try { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 175 | $notify->add({filter => $filter, | ||||||||||||||||||||||||||||||||
| 176 | owner_id => $args{owner_id}, | ||||||||||||||||||||||||||||||||
| 177 | 1 | event => "testrun_finished", | |||||||||||||||||||||||||||||||
| 178 | }); | ||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 180 | 0 | $exception = "Successfully created your testrun with id $testrun_id but failed to add a notification request\n$_"; | |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | 1 | } | |||||||||||||||||||||||||||||||
| 183 | 12 | }); | |||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 186 | 0 | $exception = $_; | |||||||||||||||||||||||||||||||
| 187 | 12 | }; | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | 12 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 190 | 0 | return ( $testrun_id, $exception ); | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||
| 193 | 12 | ▶ | if ( $exception ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | 0 | die $exception; | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | 12 | return $testrun_id; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | sub update { | ||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 204 | 1 | my ($self, $id, $args) = @_; | |||||||||||||||||||||||||||||||
| 205 | 1 | my %args = %{$args}; # copy | |||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 1 | my $testrun = $self->schema->resultset('Testrun')->find($id); | |||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | $args{owner_id} = $args{owner_id} || Tapper::Model::get_or_create_owner( $args{owner} ) if $args{owner}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{'owner_id'} || Tapper::Model::get_or_create_owner($args{'owner'})
MC/DC0%0/2
$args{'owner_id'} || Tapper::Model::get_or_create_owner($args{'owner'})
$args{'owner_id'}
Tapper::Model::get_or_create_owner($args{'owner'})
Truth table0%0/3
A || B
A= $args{'owner_id'}B= Tapper::Model::get_or_create_owner($args{'owner'})
| |||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 1 | return $testrun->update_content(\%args); | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | sub del { | ||||||||||||||||||||||||||||||
|
Subroutine
del: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 216 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||
| 217 | 1 | my $testrun = $self->schema->resultset('Testrun')->find($id); | |||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | if ($testrun->testrun_scheduling) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | return "Running testruns can not be deleted. Try freehost or wait till the testrun is finished." | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | if $testrun->testrun_scheduling->status eq 'running'; | ||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | if ($testrun->testrun_scheduling->requested_hosts->count) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 222 | 1 | foreach my $host ($testrun->testrun_scheduling->requested_hosts->all) { | |||||||||||||||||||||||||||||||
| 223 | 1 | $host->delete(); | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | if ($testrun->testrun_scheduling->requested_features->count) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | 1 | foreach my $feat ($testrun->testrun_scheduling->requested_features->all) { | |||||||||||||||||||||||||||||||
| 228 | 1 | $feat->delete(); | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 1 | $testrun->delete(); | |||||||||||||||||||||||||||||||
| 234 | 1 | return 0; | |||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | sub rerun { | ||||||||||||||||||||||||||||||
|
Subroutine
rerun: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 239 | 1 | my ($self, $id, $args) = @_; | |||||||||||||||||||||||||||||||
| 240 | 1 | ▶ | my %args = %{$args || {}}; # copy | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||
| 241 | 1 | my $testrun = $self->schema->resultset('Testrun')->find( $id ); | |||||||||||||||||||||||||||||||
| 242 | 1 | return $testrun->rerun(\%args)->id; | |||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub pause { | ||||||||||||||||||||||||||||||
|
Subroutine
pause: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 247 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||
| 248 | 0 | my $testrun = $self->schema->resultset('TestrunScheduling')->search | |||||||||||||||||||||||||||||||
| 249 | ({ | ||||||||||||||||||||||||||||||||
| 250 | testrun_id => $id, | ||||||||||||||||||||||||||||||||
| 251 | status => 'schedule', | ||||||||||||||||||||||||||||||||
| 252 | })->first; | ||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ($testrun and $testrun->testrun_id) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$testrun and $testrun->testrun_id
MC/DC0%0/2
$testrun and $testrun->testrun_id
$testrun
$testrun->testrun_id
Truth table0%0/3
A and B
A= $testrunB= $testrun->testrun_id
| |||||||||||||||||||||||||||||||||
| 254 | 0 | return $testrun->update_content({status => 'prepare'}); | |||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||
| 256 | 0 | return; | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub continue { | ||||||||||||||||||||||||||||||
|
Subroutine
continue: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 261 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||
| 262 | 0 | my $testrun = $self->schema->resultset('TestrunScheduling')->search | |||||||||||||||||||||||||||||||
| 263 | ({ | ||||||||||||||||||||||||||||||||
| 264 | testrun_id => $id, | ||||||||||||||||||||||||||||||||
| 265 | status => 'prepare', | ||||||||||||||||||||||||||||||||
| 266 | })->first; | ||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ($testrun and $testrun->testrun_id) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$testrun and $testrun->testrun_id
MC/DC0%0/2
$testrun and $testrun->testrun_id
$testrun
$testrun->testrun_id
Truth table0%0/3
A and B
A= $testrunB= $testrun->testrun_id
| |||||||||||||||||||||||||||||||||
| 268 | 0 | return $testrun->update_content({status => 'schedule'}); | |||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||
| 270 | 0 | return; | |||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | sub cancel | ||||||||||||||||||||||||||||||||
| 275 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 276 | 2 | my ($self, $testrun_id, $comment) = @_; | |||||||||||||||||||||||||||||||
| 277 | 2 | my $msg = { 'state' => 'quit', }; | |||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | if ( $comment ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 279 | 1 | $msg->{error} = $comment; | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | my $testrun_result = $self->schema->resultset('Testrun')->find( $testrun_id ) or die "No such testrun '$testrun_id'\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 282 | 2 | ▶ | if ($testrun_result->testrun_scheduling->status eq 'schedule' or | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$testrun_result->testrun_scheduling->status eq "schedule" or $testrun_result->testrun_scheduling->status eq "prepare"
MC/DC50%1/2
$testrun_result->testrun_scheduling->status eq "schedule" or $testrun_result->testrun_scheduling->status eq "prepare"
$testrun_result->testrun_scheduling->status eq "schedule"
$testrun_result->testrun_scheduling->status eq "prepare"
Truth table66%2/3
A or B
A= $testrun_result->testrun_scheduling->status eq "schedule"B= $testrun_result->testrun_scheduling->status eq "prepare"
| |||||||||||||||||||||||||||||||||
| 283 | $testrun_result->testrun_scheduling->status eq 'prepare' | ||||||||||||||||||||||||||||||||
| 284 | ) { | ||||||||||||||||||||||||||||||||
| 285 | 1 | $testrun_result->testrun_scheduling->status('finished'); | |||||||||||||||||||||||||||||||
| 286 | 1 | $testrun_result->testrun_scheduling->update; | |||||||||||||||||||||||||||||||
| 287 | } elsif ( $testrun_result->testrun_scheduling->status eq 'running') { | ||||||||||||||||||||||||||||||||
| 288 | 1 | $self->schema->resultset('Message')->new({ | |||||||||||||||||||||||||||||||
| 289 | testrun_id => $testrun_id, | ||||||||||||||||||||||||||||||||
| 290 | message => $msg, | ||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||
| 292 | )->insert; | ||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||
| 294 | 2 | return 0; | |||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | sub status | ||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=8 SCAR=31.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 301 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||
| 302 | 1 | my $result; | |||||||||||||||||||||||||||||||
| 303 | 1 | my $testrun = $self->schema->resultset('Testrun')->find($id); | |||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | die "No testrun with id '$id'\n" if not $testrun; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 1 | $result->{status} .= $testrun->testrun_scheduling->status; # the dot (.=) stringifies the enum object that the status actually contains | |||||||||||||||||||||||||||||||
| 307 | 1 | $result->{success_ratio} = undef; | |||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | 1 | my $reportgroup = $self->schema->resultset('ReportgroupTestrun')->search({testrun_id => $id}); | |||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | if ($reportgroup->count > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 311 | 0 | $result->{reports} = []; | |||||||||||||||||||||||||||||||
| 312 | 0 | foreach my $group_element ($reportgroup->all) { | |||||||||||||||||||||||||||||||
| 313 | 0 | push @{$result->{reports}}, $group_element->report_id; | |||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $result->{primaryreport} = $group_element->report_id if $group_element->primaryreport; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | if ($result->{status} eq 'finished') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 319 | 0 | my $stats = $self->schema->resultset('ReportgroupTestrunStats')->search({testrun_id => $id})->first; | |||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | return $result if not defined($stats); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 0 | $result->{success_ratio} = $stats->success_ratio; | |||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($stats->success_ratio < 100) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 324 | 0 | $result->{status} = 'fail'; | |||||||||||||||||||||||||||||||
| 325 | } else { | ||||||||||||||||||||||||||||||||
| 326 | 0 | $result->{status} = 'pass'; | |||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | 1 | return $result; | |||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | 6 | 1; # End of Tapper::Cmd::Testrun | |||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | __END__ | ||||||||||||||||||||||||||||||||