Skip to content

Commit

Permalink
Merge pull request #5964 from perlpunk/js-timezone
Browse files Browse the repository at this point in the history
Return timestamps with offset to client for needle info
  • Loading branch information
mergify[bot] authored Oct 21, 2024
2 parents 5cfb4dc + 18f4cef commit 0030e84
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
8 changes: 8 additions & 0 deletions lib/OpenQA/Schema/Result/Needles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,12 @@ sub to_json ($self) {
};
}

my $fmt = '%Y-%m-%dT%H:%M:%S%z'; # with offset
sub last_seen_time_fmt ($self) {
$self->last_seen_time ? $self->last_seen_time->strftime($fmt) : 'never';
}
sub last_matched_time_fmt ($self) {
$self->last_matched_time ? $self->last_matched_time->strftime($fmt) : 'never';
}

1;
4 changes: 2 additions & 2 deletions lib/OpenQA/WebAPI/Plugin/Helpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ sub register ($self, $app, $config) {
populate_hash_with_needle_timestamps_and_urls => sub {
my ($c, $needle, $hash) = @_;

$hash->{last_seen} = $needle ? $needle->last_seen_time || 'never' : 'unknown';
$hash->{last_match} = $needle ? $needle->last_matched_time || 'never' : 'unknown';
$hash->{last_seen} = $needle ? $needle->last_seen_time_fmt : 'unknown';
$hash->{last_match} = $needle ? $needle->last_matched_time_fmt : 'unknown';
return $hash unless $needle;
if (my $last_seen_module_id = $needle->last_seen_module_id) {
$hash->{last_seen_link} = $c->url_for(
Expand Down
8 changes: 4 additions & 4 deletions t/fixtures/07-needles.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
last_seen_module_id => 10,
# keep the timestamps aligned with 05-job_modules
# (and don't use UTC as we use it in browser tests)
last_seen_time => time2str('%Y-%m-%d %H:%M:%S', time - 100000),
last_seen_time => time2str('%Y-%m-%d %H:%M:%S', time - 100000, 'UTC'),
last_matched_module_id => 9,
last_matched_time => time2str('%Y-%m-%d %H:%M:%S', time - 50000),
last_matched_time => time2str('%Y-%m-%d %H:%M:%S', time - 50000, 'UTC'),
file_present => 1,
t_created => time2str('%Y-%m-%d %H:%M:%S', time - 200000),
t_updated => time2str('%Y-%m-%d %H:%M:%S', time - 200000),
t_created => time2str('%Y-%m-%d %H:%M:%S', time - 200000, 'UTC'),
t_updated => time2str('%Y-%m-%d %H:%M:%S', time - 200000, 'UTC'),
}

]
3 changes: 2 additions & 1 deletion t/ui/18-tests-details.t
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,9 @@ subtest 'test candidate list' => sub {
qr/Last match.*T.*Last seen.*T.*/s,
'last match and last seen shown',
);
$driver->find_element_by_id('candidatesMenu')->click();
$driver->find_element('#needlediff_selector .show-needle-info')->click();
wait_until_element_gone('.needle-info-table');
$driver->find_element('#candidatesMenu')->click();
};

# set job 99963 to done via API to tests whether worker is still displayed then
Expand Down
12 changes: 5 additions & 7 deletions t/ui/21-admin-needles.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Copyright 2014-2020 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

BEGIN { $ENV{TZ} = 'UTC' } # make sure Selenium uses the same timezone as the server

use Test::Most;

use FindBin;
Expand Down Expand Up @@ -147,12 +145,12 @@ subtest 'dereference symlink when displaying needles info' => sub {
dir_id => $real_needle_dir_id,
filename => 'bootloader.json',
last_seen_module_id => 10,
last_seen_time => time2str('%Y-%m-%d %H:%M:%S', time - 100000),
last_seen_time => time2str('%Y-%m-%d %H:%M:%S', time - 100000, 'UTC'),
last_matched_module_id => 9,
last_matched_time => time2str('%Y-%m-%d %H:%M:%S', time - 50000),
last_matched_time => time2str('%Y-%m-%d %H:%M:%S', time - 50000, 'UTC'),
file_present => 1,
t_created => time2str('%Y-%m-%d %H:%M:%S', time - 200000),
t_updated => time2str('%Y-%m-%d %H:%M:%S', time - 200000),
t_created => time2str('%Y-%m-%d %H:%M:%S', time - 200000, 'UTC'),
t_updated => time2str('%Y-%m-%d %H:%M:%S', time - 200000, 'UTC'),
});
push @need_deleted_needles, $real_needle;

Expand All @@ -170,7 +168,7 @@ subtest 'dereference symlink when displaying needles info' => sub {
is($last_used_td->get_text(), 'a day ago', 'symlink needle last use is displayed correctly');
is(
$last_used_td->child('a')->get_attribute('title'),
$real_needle->last_seen_time . 'Z',
$real_needle->last_seen_time . '+0000Z',
'symlink needle last use tooltip is displayed correctly'
);
like(
Expand Down

0 comments on commit 0030e84

Please sign in to comment.