« lib/Test2/Harness/UI/Controller/User.pm
↑ Summary
lib/Test2/Harness/UI/Schema/Overlay/Project.pm »
| 1 | package Test2::Harness::UI::BackFill; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | our $VERSION = '0.000150'; | ||
| 6 | |||
| 7 | use Data::Dumper; | ||
| 8 | use Test2::Harness::UI::UUID qw/gen_uuid/; | ||
| 9 | use Test2::Harness::UI::Util qw/parse_duration is_invalid_subtest_name/; | ||
| 10 | |||
| 11 | use Test2::Harness::UI::Util::HashBase qw{ | ||
| 12 | <config | ||
| 13 | }; | ||
| 14 | |||
| 15 | sub backfill_durations { | ||
| 16 | my $self = shift; | ||
| 17 | |||
| 18 | my $runs = $self->config->schema->resultset('Run')->search( | ||
| 19 | {status => {'-in' => [qw/complete canceled/]}}, | ||
| 20 | {order_by => 'run_ord',} | ||
| 21 | ); | ||
| 22 | |||
| 23 | while (my $run = $runs->next) { | ||
| 24 | if ($run->reportings->count) { | ||
| 25 | print "Run " . $run->run_id . " is already populated with durations data.\n"; | ||
| 26 | next; | ||
| 27 | } | ||
| 28 | |||
| 29 | my $buffer = []; | ||
| 30 | print "Starting run " . $run->run_id . "...\n"; | ||
| 31 | |||
| 32 | my %run_data = ( | ||
| 33 | project_id => $run->project_id, | ||
| 34 | run_id => $run->run_id, | ||
| 35 | run_ord => $run->run_ord, | ||
| 36 | user_id => $run->user_id, | ||
| 37 | ); | ||
| 38 | |||
| 39 | if (my $duration = $run->duration) { | ||
| 40 | my $fail = $run->failed ? 1 : 0; | ||
| 41 | my $pass = $run->failed ? 0 : 1; | ||
| 42 | my $abort = $run->status ne 'complete' ? 1 : 0; | ||
| 43 | $fail = 0 if $abort; | ||
| 44 | $pass = 0 if $abort; | ||
| 45 | |||
| 46 | push @$buffer => { | ||
| 47 | %run_data, | ||
| 48 | reporting_id => gen_uuid(), | ||
| 49 | duration => parse_duration($duration), | ||
| 50 | retry => 0, | ||
| 51 | pass => $pass, | ||
| 52 | fail => $fail, | ||
| 53 | abort => $abort, | ||
| 54 | }; | ||
| 55 | } | ||
| 56 | |||
| 57 | my $jobs = $run->jobs; | ||
| 58 | while (my $job = $jobs->next) { | ||
| 59 | next unless $job->test_file_id; | ||
| 60 | |||
| 61 | print " Starting job " . $job->test_file->filename . " " . ($job->job_try || 0) . "...\n"; | ||
| 62 | my %job_data = ( | ||
| 63 | %run_data, | ||
| 64 | job_try => $job->job_try // 0, | ||
| 65 | job_key => $job->job_key, | ||
| 66 | test_file_id => $job->test_file_id, | ||
| 67 | ); | ||
| 68 | |||
| 69 | if (my $duration = $job->duration) { | ||
| 70 | my $fail = $job->fail ? 1 : 0; | ||
| 71 | my $pass = $job->fail ? 0 : 1; | ||
| 72 | my $retry = $job->retry ? 1 : 0; | ||
| 73 | my $abort = $job->ended ? 0 : 1; | ||
| 74 | |||
| 75 | push @$buffer => { | ||
| 76 | %job_data, | ||
| 77 | reporting_id => gen_uuid(), | ||
| 78 | duration => parse_duration($duration), | ||
| 79 | pass => $pass, | ||
| 80 | fail => $fail, | ||
| 81 | retry => $retry, | ||
| 82 | abort => $abort, | ||
| 83 | }; | ||
| 84 | } | ||
| 85 | |||
| 86 | my $events = $job->events->search({is_subtest => 1, nested => 0}); | ||
| 87 | while (my $e = $events->next()) { | ||
| 88 | my $f = $e->facets or next; | ||
| 89 | next if $f->{hubs}->[0]->{nested}; | ||
| 90 | |||
| 91 | my $parent = $f->{parent} // next; | ||
| 92 | my $assert = $f->{assert} // next; | ||
| 93 | my $st = $assert->{details} // next; | ||
| 94 | next if is_invalid_subtest_name($st); | ||
| 95 | |||
| 96 | my $start = $parent->{start_stamp} // next; | ||
| 97 | my $stop = $parent->{stop_stamp} // next; | ||
| 98 | my $duration = $stop - $start // next; | ||
| 99 | |||
| 100 | print " Adding subtest '$st'\n"; | ||
| 101 | push @$buffer => { | ||
| 102 | %job_data, | ||
| 103 | reporting_id => gen_uuid(), | ||
| 104 | duration => $duration, | ||
| 105 | subtest => $st, | ||
| 106 | event_id => $e->event_id, | ||
| 107 | abort => 0, | ||
| 108 | retry => 0, | ||
| 109 | $assert->{pass} ? (pass => 1, fail => 0) : (fail => 1, pass => 0), | ||
| 110 | }; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | unless (@$buffer) { | ||
| 115 | print "No durations to add.\n\n"; | ||
| 116 | next; | ||
| 117 | } | ||
| 118 | |||
| 119 | local $ENV{DBIC_DT_SEARCH_OK} = 1; | ||
| 120 | unless (eval { $self->config->schema->resultset('Reporting')->populate($buffer); 1 }) { | ||
| 121 | warn "Failed to populate reporting!\n$@\n" . Dumper($buffer); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | 1; |