Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use needles from correct ref of NEEDLES_DIR #5175

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/OpenQA/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mojo::Base -base, -signatures;
use Mojo::Util 'trim';
use Cwd 'abs_path';
use File::Touch;
use Mojo::File 'path';
use OpenQA::Utils qw(run_cmd_with_log_return_error);

has 'app';
Expand Down Expand Up @@ -146,16 +146,16 @@
return $r->{status};
}

sub cache_ref ($self, $ref, $relative_path, $output_file) {
if (-f $output_file) {
eval { touch $output_file };
eval { path($output_file)->touch };
return $@ ? $@ : undef;

Check warning on line 152 in lib/OpenQA/Git.pm

View check run for this annotation

Codecov / codecov/patch

lib/OpenQA/Git.pm#L149-L152

Added lines #L149 - L152 were not covered by tests
}
my @git = $self->_prepare_git_command;
my $res = run_cmd_with_log_return_error [@git, 'show', "$ref:./$relative_path"], output_file => $output_file;
return undef if $res->{status};
unlink $output_file;
return _format_git_error($res, 'Unable to cache Git ref');

Check warning on line 158 in lib/OpenQA/Git.pm

View check run for this annotation

Codecov / codecov/patch

lib/OpenQA/Git.pm#L154-L158

Added lines #L154 - L158 were not covered by tests
}

1;
14 changes: 10 additions & 4 deletions t/14-grutasks.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use OpenQA::Test::Case;
use File::Which 'which';
use File::Path ();
use Mojo::Util qw(dumper scope_guard);
use File::Touch ();
use Date::Format 'time2str';
use Fcntl ':mode';
use Mojo::File qw(path tempdir);
Expand Down Expand Up @@ -418,9 +417,16 @@ subtest 'limit_temp_needle_refs task cleans up temp needle refs exceeding retent
$temp_dir->child($_)->make_path for qw(ref1 ref2);
my @old_needle_files = ("$temp_dir/ref1/needle_old.png", "$temp_dir/ref1/needle_old.json");
my @new_needle_files = ("$temp_dir/ref2/needle_new.png", "$temp_dir/ref2/needle_new.json");
my $now = time;
File::Touch->new(time => $now - (120 * ONE_MINUTE + 1))->touch(@old_needle_files);
File::Touch->new(time => $now + ONE_MINUTE)->touch(@new_needle_files);
my $old_timestamp = time - (120 * ONE_MINUTE + 1);
my $new_timestamp = time - ONE_MINUTE + 1;
Comment on lines +420 to +421
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid repeated calls to time.

foreach my $file (@old_needle_files) {
path($file)->touch;
utime $old_timestamp, $old_timestamp, $file;
}
foreach my $file (@new_needle_files) {
path($file)->touch;
utime $new_timestamp, $new_timestamp, $file;
}

# enqueue and run cleanup
my $minion = $t->app->minion;
Expand Down
Loading