Tapper/RawSQL/TestrunDB/testruns.pm

filter: Statementstmt 21.4% 9 / 42 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 14.4% 11 / 76 CC 13 SCAR 50.0
CC
13
Cov
14%
web_list
182.0
continuous_list
2.0
BEGIN
1.0
CRAP 148.1
« Tapper/RawSQL/TestrunDB/reports.pm ↑ Summary Tapper/RawSQL/ReportsDB/reports.pm »
1 package Tapper::RawSQL::TestrunDB::testruns;
2 1 our $AUTHORITY = 'cpan:TAPPER';
3 1 $Tapper::RawSQL::TestrunDB::testruns::VERSION = '5.0.12';
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub web_list {
Subroutine web_list: not called CC=13 SCAR=52.0
Pod undocumented
8  
9 0 my ( $hr_vals ) = @_;
10  
11 0 my @a_where;
12 0 my $b_essentials = 0;
13 0 ▶ if ( $hr_vals->{testrun_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_vals->{"testrun_id"}) 0 0 0
14 0 $b_essentials = 1;
15 }
16 0 ▶ if ( $hr_vals->{testrun_date_from} && $hr_vals->{testrun_date_to} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_vals->{"testrun_date_from"} and $hr_vals->{"testrun_date_to"}) 0 0 0
Condition0%0/3
$hr_vals->{"testrun_date_from"} and $hr_vals->{"testrun_date_to"}
!ll&&!rl&&r
000
MC/DC0%0/2
$hr_vals->{"testrun_date_from"} and $hr_vals->{"testrun_date_to"}
$hr_vals->{"testrun_date_from"} $hr_vals->{"testrun_date_to"}
Truth table0%0/3
A and B
A= $hr_vals->{"testrun_date_from"}B= $hr_vals->{"testrun_date_to"}
ABresult
0X0
100
111
17 0 $hr_vals->{testrun_date_min} = "$hr_vals->{testrun_date_from} 00:00:00";
18 0 $hr_vals->{testrun_date_max} = "$hr_vals->{testrun_date_to} 23:59:59";
19 0 push @a_where, 't.updated_at BETWEEN $testrun_date_min$ AND $testrun_date_max$';
20 0 $b_essentials = 1;
21 }
22  
23 0 ▶ if (! $b_essentials ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($b_essentials) 0 0 0
24 0 require Carp;
25 0 Carp::croak('missing parameters for sql statement: testruns::web_list');
26 }
27  
28 0 my %h_where_columns = (
29 testrun_id => 't.id',
30 host => 'ts.host_id',
31 state => 'ts.status',
32 owner => 't.owner_id',
33 topic => 't.topic_name',
34 success => 'r.successgrade',
35 );
36  
37 0 for my $s_filter ( keys %h_where_columns ) {
38 0 ▶ if ( $hr_vals->{$s_filter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_vals->{$s_filter}) 0 0 0
39 0 ▶ if ( ref $hr_vals->{$s_filter} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hr_vals->{$s_filter} eq 'ARRAY') { } 0 0 0
40 0 ▶ if ( @{$hr_vals->{$s_filter}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$hr_vals->{$s_filter};}) 0 0 0
41 0 ▶ if ( @{$hr_vals->{$s_filter}} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$hr_vals->{$s_filter};} == 1) { } 0 0 0
42 0 push @a_where, "$h_where_columns{$s_filter} = \$$s_filter\$";
43 }
44 else {
45 0 push @a_where, "$h_where_columns{$s_filter} IN (\$$s_filter\$)";
46 }
47 }
48 }
49 else {
50 0 push @a_where, "$h_where_columns{$s_filter} = \$$s_filter\$";
51 }
52 }
53 }
54  
55 0 ▶ if ( defined $hr_vals->{resource} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hr_vals->{"resource"}) 0 0 0
56 0 my $inner_condition;
57 0 ▶ if ( ref $hr_vals->{resource} eq 'ARRAY' && @{$hr_vals->{resource}} != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hr_vals->{'resource'} eq 'ARRAY' and @{$hr_vals->{'resource'};} != 1) { } 0 0 0
Condition0%0/3
ref $hr_vals->{"resource"} eq "ARRAY" and @{$hr_vals->{"resource"};} != 1
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hr_vals->{"resource"} eq "ARRAY" and @{$hr_vals->{"resource"};} != 1
ref $hr_vals->{"resource"} eq "ARRAY" @{$hr_vals->{"resource"};} != 1
Truth table0%0/3
A and B
A= ref $hr_vals->{"resource"} eq "ARRAY"B= @{$hr_vals->{"resource"};} != 1
ABresult
0X0
100
111
58 0 $inner_condition = 'trr.selected_resource_id IN ($resource$)';
59 } else {
60 0 $inner_condition = 'trr.selected_resource_id = $resource$';
61 }
62  
63 0 push @a_where, "EXISTS(SELECT trr.id FROM testrun_requested_resource trr WHERE trr.testrun_id = t.id AND $inner_condition)";
64 }
65  
66  
67 return {
68 0 Pg => q#
69 SELECT
70 t.id AS testrun_id,
71 FLOOR( CAST( NULLIF( rgts.success_ratio, 0 ) AS float ) ) AS success_ratio,
72 r.successgrade,
73 r.id AS primary_report_id,
74 t.topic_name,
75 TO_CHAR( r.updated_at, 'YYYY-MM-DD' ) AS testrun_date,
76 TO_CHAR( r.updated_at, 'HH24:MM' ) AS testrun_time,
77 NULLIF( r.updated_at, t.updated_at ) AS updated_at,
78 NULLIF( o.login, 'unknown user' ) AS testrun_owner,
79 t.starttime_testrun,
80 NULLIF( ts.status, 'unknown status' ) AS testrun_state,
81 IF(
82 ts.id IS NULL,
83 'unknownmachine',
84 IF(
85 h.id IS NULL,
86 IF(
87 ts.status = 'finished',
88 'Host deleted',
89 'No host assigned'
90 ),
91 h.name
92 )
93 ) AS machine_name
94 FROM
95 testrun t
96 LEFT JOIN owner o
97 ON ( o.id = t.owner_id )
98 LEFT JOIN (
99 reportgrouptestrunstats rgts
100 JOIN reportgrouptestrun rgt
101 ON ( rgt.testrun_id = rgts.testrun_id )
102 JOIN report r
103 ON ( r.id = rgt.report_id )
104 LEFT JOIN suite s
105 ON ( r.suite_id = s.id )
106 )
107 ON (
108 rgts.testrun_id = t.id
109 AND rgt.report_id = (
110 SELECT
111 rgti.report_id
112 FROM
113 reportgrouptestrun rgti
114 WHERE
115 rgti.testrun_id = rgt.testrun_id
116 ORDER BY
117 rgti.primaryreport DESC,
118 rgti.report_id ASC
119 LIMIT
120 1
121 )
122 )
123 LEFT JOIN (
124 testrun_scheduling ts
125 LEFT JOIN host h
126 ON ( h.id = ts.host_id )
127 )
128 ON ( ts.testrun_id = t.id )
129 WHERE
130 # . ( join "\nAND ", @a_where ) . q#
131 ORDER BY
132 t.id DESC
133 #,
134 SQLite => q#
135 SELECT
136 t.id AS testrun_id,
137 CAST( IFNULL( rgts.success_ratio, 0 ) AS INT ) AS success_ratio,
138 r.successgrade,
139 r.id AS primary_report_id,
140 t.topic_name,
141 STRFTIME( '%Y-%m-%d', r.updated_at ) AS testrun_date,
142 STRFTIME( '%H:%M', r.updated_at ) AS testrun_time,
143 IFNULL( r.updated_at, t.updated_at ) AS updated_at,
144 IFNULL( o.login, 'unknown user' ) AS testrun_owner,
145 t.starttime_testrun,
146 IFNULL( ts.status, 'unknown status' ) AS testrun_state,
147 CASE WHEN
148 ts.id IS NULL
149 THEN
150 'unknownmachine'
151 ELSE
152 CASE WHEN
153 h.id IS NULL
154 THEN
155 CASE WHEN
156 ts.status = 'finished'
157 THEN
158 'Host deleted'
159 ELSE
160 'No host assigned'
161 END
162 ELSE
163 h.name
164 END
165 END AS machine_name
166 FROM
167 testrun t
168 LEFT JOIN owner o
169 ON ( o.id = t.owner_id )
170 LEFT JOIN (
171 reportgrouptestrunstats rgts
172 JOIN reportgrouptestrun rgt
173 ON ( rgt.testrun_id = rgts.testrun_id )
174 JOIN report r
175 ON ( r.id = rgt.report_id )
176 LEFT JOIN suite s
177 ON ( r.suite_id = s.id )
178 )
179 ON (
180 rgts.testrun_id = t.id
181 AND rgt.report_id = (
182 SELECT
183 rgti.report_id
184 FROM
185 reportgrouptestrun rgti
186 WHERE
187 rgti.testrun_id = rgt.testrun_id
188 ORDER BY
189 rgti.primaryreport DESC,
190 rgti.report_id ASC
191 LIMIT
192 1
193 )
194 )
195 LEFT JOIN (
196 testrun_scheduling ts
197 LEFT JOIN host h
198 ON ( h.id = ts.host_id )
199 )
200 ON ( ts.testrun_id = t.id )
201 WHERE
202 # . ( join "\nAND ", @a_where ) . q#
203 ORDER BY
204 t.id DESC
205 #,
206 mysql => q#
207 SELECT
208 t.id AS testrun_id,
209 FLOOR( IFNULL( rgts.success_ratio, 0 ) ) AS success_ratio,
210 r.successgrade,
211 r.id AS primary_report_id,
212 t.topic_name,
213 DATE_FORMAT( t.updated_at, '%Y-%m-%d' ) AS testrun_date,
214 DATE_FORMAT( t.updated_at, '%H:%i' ) AS testrun_time,
215 IFNULL( r.updated_at, t.updated_at ) AS updated_at,
216 IFNULL( o.login, 'unknown user' ) AS testrun_owner,
217 t.starttime_testrun,
218 IFNULL( ts.status, 'unknown status' ) AS testrun_state,
219 IF(
220 ts.id IS NULL,
221 'unknownmachine',
222 IF(
223 h.id IS NULL,
224 IF(
225 ts.status = 'finished',
226 'Host deleted',
227 'No host assigned'
228 ),
229 h.name
230 )
231 ) AS machine_name
232 FROM
233 testrundb.testrun t
234 LEFT JOIN testrundb.owner o
235 ON ( o.id = t.owner_id )
236 LEFT JOIN (
237 testrundb.reportgrouptestrunstats rgts
238 JOIN testrundb.reportgrouptestrun rgt
239 ON ( rgt.testrun_id = rgts.testrun_id )
240 JOIN testrundb.report r
241 ON ( r.id = rgt.report_id )
242 LEFT JOIN testrundb.suite s
243 ON ( r.suite_id = s.id )
244 )
245 ON (
246 rgts.testrun_id = t.id
247 AND rgt.report_id = (
248 SELECT
249 rgti.report_id
250 FROM
251 testrundb.reportgrouptestrun rgti
252 WHERE
253 rgti.testrun_id = rgt.testrun_id
254 ORDER BY
255 rgti.primaryreport DESC,
256 rgti.report_id ASC
257 LIMIT
258 1
259 )
260 )
261 LEFT JOIN (
262 testrundb.testrun_scheduling ts
263 LEFT JOIN testrundb.host h
264 ON ( h.id = ts.host_id )
265 )
266 ON ( ts.testrun_id = t.id )
267 WHERE
268 # . ( join "\nAND ", @a_where ) . q#
269 ORDER BY
270 t.id DESC
271 #,
272 };
273 }
274  
275 0 ▶sub continuous_list {
Subroutine continuous_list: not called CC=1 SCAR=6.9
Pod undocumented
276 return {
277 0 'Pg' => q#
278 SELECT
279 t.id AS testrun_id,
280 TO_CHAR( r.updated_at, 'YYYY-MM-DD HH24:MM' ) AS testrun_date,
281 ts.status,
282 t.topic_name,
283 q.name AS queue_name,
284 STRING_AGG( h.name, ',' ) AS hosts,
285 NULLIF( o.name, o.login ) AS owner,
286 (SELECT res.name FROM resource res INNER JOIN testrun_requested_resource_alternative trra ON ( res.id = trra.resource_id )
287 INNER JOIN testrun_requested_resource trr ON ( trra.request_id = trr.id )
288 WHERE trr.testrun_id = t.id LIMIT 1) AS resource
289 FROM
290 testrun t
291 JOIN testrun_scheduling ts
292 ON ( t.id = ts.testrun_id )
293 JOIN owner o
294 ON ( t.owner_id = o.id )
295 JOIN testrun_requested_host trh
296 ON ( t.id = trh.testrun_id )
297 JOIN host h
298 ON ( trh.host_id = h.id )
299 JOIN queue q
300 ON ( ts.queue_id = q.id )
301 WHERE
302 ts.auto_rerun = 1
303 AND ts.status IN ( 'prepare', 'schedule' )
304 GROUP BY
305 t.id,
306 t.updated_at,
307 ts.status,
308 t.topic_name,
309 queue_name,
310 owner
311 ORDER BY
312 t.id DESC
313 #,
314 'SQLite' => q#
315 SELECT
316 t.id AS testrun_id,
317 STRFTIME( '%Y-%m-%d %H:%M', t.updated_at ) AS testrun_date,
318 ts.status,
319 t.topic_name,
320 q.name AS queue_name,
321 GROUP_CONCAT( h.name ) AS hosts,
322 IFNULL( o.name, o.login ) AS owner,
323 (SELECT res.name FROM resource res
324 INNER JOIN testrun_requested_resource_alternative trra ON ( res.id = trra.resource_id )
325 INNER JOIN testrun_requested_resource trr ON ( trra.request_id = trr.id )
326 WHERE trr.testrun_id = t.id LIMIT 1) AS resource
327 FROM
328 testrun t
329 JOIN testrun_scheduling ts
330 ON ( t.id = ts.testrun_id )
331 JOIN owner o
332 ON ( t.owner_id = o.id )
333 JOIN testrun_requested_host trh
334 ON ( t.id = trh.testrun_id )
335 JOIN host h
336 ON ( trh.host_id = h.id )
337 JOIN queue q
338 ON ( ts.queue_id = q.id )
339 WHERE
340 ts.auto_rerun = 1
341 AND ts.status IN ( 'prepare', 'schedule' )
342 GROUP BY
343 t.id,
344 t.updated_at,
345 ts.status,
346 t.topic_name,
347 queue_name,
348 owner
349 ORDER BY
350 t.id DESC
351 #,
352 'mysql' => q#
353 SELECT
354 t.id AS testrun_id,
355 DATE_FORMAT( t.updated_at, '%Y-%m-%d %H:%i' ) AS testrun_date,
356 ts.status,
357 t.topic_name,
358 q.name AS queue_name,
359 GROUP_CONCAT( h.name ORDER BY h.name ) AS hosts,
360 IFNULL( o.name, o.login ) AS owner,
361 (SELECT res.name FROM resource res INNER JOIN testrun_requested_resource_alternative trra ON ( res.id = trra.resource_id )
362 INNER JOIN testrun_requested_resource trr ON ( trra.request_id = trr.id )
363 WHERE trr.testrun_id = t.id LIMIT 1) AS resource
364 FROM
365 testrundb.testrun t
366 JOIN testrundb.testrun_scheduling ts
367 ON ( t.id = ts.testrun_id )
368 JOIN testrundb.owner o
369 ON ( t.owner_id = o.id )
370 JOIN testrundb.testrun_requested_host trh
371 ON ( t.id = trh.testrun_id )
372 JOIN testrundb.host h
373 ON ( trh.host_id = h.id )
374 JOIN queue q
375 ON ( ts.queue_id = q.id )
376 WHERE
377 ts.auto_rerun = 1
378 AND ts.status IN ( 'prepare', 'schedule' )
379 GROUP BY
380 t.id,
381 t.updated_at,
382 ts.status,
383 t.topic_name,
384 queue_name,
385 owner
386 ORDER BY
387 t.id DESC
388 #,
389 };
390 }
391  
392 1 1;
393  
394 __END__
« Tapper/RawSQL/TestrunDB/reports.pm ↑ Summary Tapper/RawSQL/ReportsDB/reports.pm »