Commit bcaf444b authored by Alexander Kutelev's avatar Alexander Kutelev Committed by Alexander Kutelev

Take contacted_at value from the DB when it is about to be displayed in the...

Take contacted_at value from the DB when it is about to be displayed in the Web interface with sorting enabled.
parent d56124b5
......@@ -28,4 +28,14 @@ module RunnersHelper
display_name + id
end
end
# Due to inability of performing sorting of runners by cached "contacted_at" values we have to show uncached values if sorting by "contacted_asc" is requested.
# Please refer to the following issue for more details: https://gitlab.com/gitlab-org/gitlab-ce/issues/55920
def runner_contacted_at(runner)
if params[:sort] == 'contacted_asc'
runner.uncached_contacted_at
else
runner.contacted_at
end
end
end
......@@ -256,6 +256,10 @@ module Ci
end
end
def uncached_contacted_at
read_attribute(:contacted_at)
end
private
def cleanup_runner_queue
......
......@@ -56,8 +56,9 @@
.table-section.section-10
.table-mobile-header{ role: 'rowheader' }= _('Last contact')
.table-mobile-content
- if runner.contacted_at
= time_ago_with_tooltip runner.contacted_at
- contacted_at = runner_contacted_at(runner)
- if contacted_at
= time_ago_with_tooltip contacted_at
- else
= _('Never')
......
......@@ -15,4 +15,40 @@ describe RunnersHelper do
runner = FactoryBot.build(:ci_runner, contacted_at: 1.second.ago, active: true)
expect(runner_status_icon(runner)).to include("Runner is online")
end
describe '#runner_contacted_at' do
let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) }
let(:contacted_at_cached) { 1.second.ago.change(usec: 0) }
let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) }
before do
runner.cache_attributes(contacted_at: contacted_at_cached)
end
context 'without sorting' do
it 'returns cached value' do
expect(runner_contacted_at(runner)).to eq(contacted_at_cached)
end
end
context 'with sorting set to created_date' do
before do
controller.params[:sort] = 'created_date'
end
it 'returns cached value' do
expect(runner_contacted_at(runner)).to eq(contacted_at_cached)
end
end
context 'with sorting set to contacted_asc' do
before do
controller.params[:sort] = 'contacted_asc'
end
it 'returns stored value' do
expect(runner_contacted_at(runner)).to eq(contacted_at_stored)
end
end
end
end
......@@ -817,4 +817,13 @@ describe Ci::Runner do
expect(runners).to eq([runner2, runner1])
end
end
describe '#uncached_contacted_at' do
let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) }
let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) }
subject { runner.uncached_contacted_at }
it { is_expected.to eq(contacted_at_stored) }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment