Commit ea293f2f authored by Tiago Botelho's avatar Tiago Botelho

add changelog entry to sync_time feature

parent 70b2b72b
---
title: Try to update mirrors again after 15 minutes if the previous update failed
merge_request: 1183
author:
...@@ -58,7 +58,7 @@ module Gitlab ...@@ -58,7 +58,7 @@ module Gitlab
end end
def true_value def true_value
if postgresql? if Gitlab::Database.postgresql?
"'t'" "'t'"
else else
1 1
...@@ -66,7 +66,7 @@ module Gitlab ...@@ -66,7 +66,7 @@ module Gitlab
end end
def false_value def false_value
if postgresql? if Gitlab::Database.postgresql?
"'f'" "'f'"
else else
0 0
......
require 'rails_helper' require 'rails_helper'
describe UpdateAllMirrorsWorker do describe UpdateAllMirrorsWorker do
before do before { allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(true) }
allow_any_instance_of(Gitlab::ExclusiveLease)
.to receive(:try_obtain).and_return(true)
end
describe '#perform' do describe '#perform' do
let(:worker) { described_class.new }
let!(:mirror1) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::FIFTEEN) } let!(:mirror1) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::FIFTEEN) }
let!(:mirror2) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::HOURLY) } let!(:mirror2) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::HOURLY) }
let!(:mirror3) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::DAILY) } let!(:mirror3) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::DAILY) }
let!(:mirror4) { create(:empty_project, :mirror) } let!(:mirror4) { create(:empty_project, :mirror) }
it 'fails stuck mirrors' do it 'fails stuck mirrors' do
worker = described_class.new
expect(worker).to receive(:fail_stuck_mirrors!) expect(worker).to receive(:fail_stuck_mirrors!)
worker.perform worker.perform
end end
describe 'update times' do describe 'sync_time' do
after do def expect_worker_to_update_mirrors(mirrors)
Timecop.return mirrors.each do |mirror|
expect(worker).to receive(:rand).with((mirror.sync_time / 2).minutes).and_return(mirror.sync_time / 2)
expect(RepositoryUpdateMirrorDispatchWorker).to receive(:perform_in).with(mirror.sync_time / 2, mirror.id)
end
end end
describe 'fifteen' do def setup(time)
before do Timecop.freeze(time)
time = DateTime.now.beginning_of_hour + 15.minutes mirror4.update_attributes(mirror_last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes)
end
Timecop.freeze(time) describe 'fifteen' do
mirror4.update_attributes(mirror_last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes) let(:mirrors) { [mirror1, mirror4] }
end
it 'enqueues a job on mirrored Projects' do before { setup(DateTime.now.beginning_of_hour + 15.minutes) }
mirrors = [mirror1, mirror4]
worker = described_class.new
mirrors.each do |mirror| it 'enqueues a job on mirrored projects' do
expect(worker).to receive(:rand).with((mirror.sync_time / 2).minutes).and_return(mirror.sync_time / 2) expect_worker_to_update_mirrors(mirrors)
expect(RepositoryUpdateMirrorDispatchWorker).to receive(:perform_in).with(mirror.sync_time / 2, mirror.id)
end
worker.perform worker.perform
end end
end end
describe 'hourly' do describe 'hourly' do
before do let(:mirrors) { [mirror1, mirror2, mirror4] }
time = DateTime.now.beginning_of_hour
Timecop.freeze(time)
mirror4.update_attributes(mirror_last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes)
end
it 'enqueues a job on mirrored Projects' do before { setup(DateTime.now.beginning_of_hour) }
mirrors = [mirror1, mirror2, mirror4]
worker = described_class.new
mirrors.each do |mirror| it 'enqueues a job on mirrored projects' do
expect(worker).to receive(:rand).with((mirror.sync_time / 2).minutes).and_return(mirror.sync_time / 2) expect_worker_to_update_mirrors(mirrors)
expect(RepositoryUpdateMirrorDispatchWorker).to receive(:perform_in).with(mirror.sync_time / 2, mirror.id)
end
worker.perform worker.perform
end end
end end
describe 'daily' do describe 'daily' do
before do let(:mirrors) { [mirror1, mirror2, mirror3, mirror4] }
time = DateTime.now.beginning_of_day
Timecop.freeze(time) before { setup(DateTime.now.beginning_of_day) }
mirror4.update_attributes(mirror_last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes)
end
it 'enqueues a job on mirrored Projects' do
mirrors = [mirror1, mirror2, mirror3, mirror4]
worker = described_class.new
mirrors.each do |mirror| it 'enqueues a job on mirrored projects' do
expect(worker).to receive(:rand).with((mirror.sync_time / 2).minutes).and_return(mirror.sync_time / 2) expect_worker_to_update_mirrors(mirrors)
expect(RepositoryUpdateMirrorDispatchWorker).to receive(:perform_in).with(mirror.sync_time / 2, mirror.id)
end
worker.perform worker.perform
end end
end end
after { Timecop.return }
end end
it 'does not execute if cannot get the lease' do it 'does not execute if cannot get the lease' do
allow_any_instance_of(Gitlab::ExclusiveLease) allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(false)
.to receive(:try_obtain).and_return(false)
worker = described_class.new
create(:empty_project, :mirror) create(:empty_project, :mirror)
expect(worker).not_to receive(:fail_stuck_mirrors!) expect(worker).not_to receive(:fail_stuck_mirrors!)
......
require 'rails_helper' require 'rails_helper'
describe UpdateAllRemoteMirrorsWorker do describe UpdateAllRemoteMirrorsWorker do
describe "#perform" do let(:worker) { described_class.new }
describe "#perform" do
let!(:mirror1) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::FIFTEEN) } let!(:mirror1) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::FIFTEEN) }
let!(:mirror2) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::HOURLY) } let!(:mirror2) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::HOURLY) }
let!(:mirror3) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::DAILY) } let!(:mirror3) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::DAILY) }
let!(:mirror4) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::DAILY) } let!(:mirror4) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::DAILY) }
it 'fails stuck mirrors' do it 'fails stuck mirrors' do
worker = described_class.new
expect(worker).to receive(:fail_stuck_mirrors!) expect(worker).to receive(:fail_stuck_mirrors!)
worker.perform worker.perform
end end
describe 'update times' do describe 'sync time' do
after do def expect_worker_to_update_mirrors(mirrors)
Timecop.return mirrors.each do |mirror|
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_async).with(mirror.id)
end
end end
describe 'fifteen' do def setup(time)
before do Timecop.freeze(time)
time = DateTime.now.beginning_of_hour + 15.minutes mirror4.remote_mirrors.first.update_attributes(last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes)
end
Timecop.freeze(time) describe 'fifteen' do
mirror4.remote_mirrors.first.update_attributes(last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes) let(:mirrors) { [mirror1, mirror4] }
end
it 'enqueues a job on mirrored Projects' do before { setup(DateTime.now.beginning_of_hour + 15.minutes) }
mirrors = [mirror1, mirror4]
worker = described_class.new
mirrors.each do |mirror| it 'enqueues a job on remote mirrored projects' do
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_async).with(mirror.id) expect_worker_to_update_mirrors(mirrors)
end
worker.perform worker.perform
end end
end end
describe "hourly" do describe "hourly" do
before do let(:mirrors) { [mirror1, mirror2, mirror4] }
time = DateTime.now.beginning_of_hour
Timecop.freeze(time)
mirror4.remote_mirrors.first.update_attributes(last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes)
end
it 'enqueues a job on mirrored Projects' do before { setup(DateTime.now.beginning_of_hour) }
mirrors = [mirror1, mirror2, mirror4]
worker = described_class.new
mirrors.each do |mirror| it 'enqueues a job on remote mirrored projects' do
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_async).with(mirror.id) expect_worker_to_update_mirrors(mirrors)
end
worker.perform worker.perform
end end
end end
describe "daily" do describe "daily" do
before do let(:mirrors) { [mirror1, mirror2, mirror3, mirror4] }
time = DateTime.now.beginning_of_day
Timecop.freeze(time) before { setup(DateTime.now.beginning_of_day) }
mirror4.remote_mirrors.first.update_attributes(last_successful_update_at: time - (Gitlab::Mirror::DAILY + 5).minutes)
end
it 'enqueues a job on mirrored Projects' do
mirrors = [mirror1, mirror2, mirror3, mirror4]
worker = described_class.new
mirrors.each do |mirror| it 'enqueues a job on remote mirrored projects' do
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_async).with(mirror.id) expect_worker_to_update_mirrors(mirrors)
end
worker.perform worker.perform
end end
end end
after { Timecop.return }
end end
end end
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