Commit c54e08cf authored by Tiago Botelho's avatar Tiago Botelho

refactors git push service spec code

parent be0f6c42
...@@ -76,7 +76,7 @@ class RemoteMirror < ActiveRecord::Base ...@@ -76,7 +76,7 @@ class RemoteMirror < ActiveRecord::Base
def sync def sync
return unless project && enabled return unless project && enabled
schedule_update_job RepositoryUpdateRemoteMirrorWorker.perform_in(BACKOFF_DELAY, self.id, Time.now) if project&.repository_exists?
end end
def updated_since?(timestamp) def updated_since?(timestamp)
...@@ -133,10 +133,6 @@ class RemoteMirror < ActiveRecord::Base ...@@ -133,10 +133,6 @@ class RemoteMirror < ActiveRecord::Base
) )
end end
def schedule_update_job
RepositoryUpdateRemoteMirrorWorker.perform_in(BACKOFF_DELAY, self.id, Time.now) if project&.repository_exists?
end
def refresh_remote def refresh_remote
return unless project return unless project
......
...@@ -5,7 +5,7 @@ class RepositoryUpdateRemoteMirrorWorker ...@@ -5,7 +5,7 @@ class RepositoryUpdateRemoteMirrorWorker
include Sidekiq::Worker include Sidekiq::Worker
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
sidekiq_options queue: :project_mirror, retry: 3 sidekiq_options queue: :project_mirror, retry: 3, dead: false
sidekiq_retry_in { |count| 30 * count } sidekiq_retry_in { |count| 30 * count }
......
...@@ -72,7 +72,7 @@ repository to push to. Hit **Save changes** for the changes to take effect. ...@@ -72,7 +72,7 @@ repository to push to. Hit **Save changes** for the changes to take effect.
Similarly to the pull mirroring, since the upstream repository functions as a Similarly to the pull mirroring, since the upstream repository functions as a
mirror to the repository in GitLab, you are advised not to push commits directly mirror to the repository in GitLab, you are advised not to push commits directly
to the mirrored repository. Instead, all changes will end up in the mirrored repository to the mirrored repository. Instead, all changes will end up in the mirrored repository
whenever commits are be pushed to GitLab, or when a [forced update](#forcing-an-update) is initiated. whenever commits are pushed to GitLab, or when a [forced update](#forcing-an-update) is initiated.
Pushes into GitLab are automatically pushed to the remote mirror 5 minutes after they come in. Pushes into GitLab are automatically pushed to the remote mirror 5 minutes after they come in.
......
...@@ -85,6 +85,38 @@ describe RemoteMirror do ...@@ -85,6 +85,38 @@ describe RemoteMirror do
end end
end end
context '#sync' do
let(:remote_mirror) { create(:project, :remote_mirror).remote_mirrors.first }
before do
Timecop.freeze(Time.now)
end
context 'with remote mirroring enabled' do
it 'schedules a RepositoryUpdateRemoteMirrorWorker to run within a certain backoff delay' do
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_in).with(RemoteMirror::BACKOFF_DELAY, remote_mirror.id, Time.now)
remote_mirror.sync
end
end
context 'with remote mirroring disabled' do
it 'returns nil' do
remote_mirror.update_attributes(enabled: false)
expect(remote_mirror.sync).to be_nil
end
end
context 'without project' do
it 'returns nil' do
allow_any_instance_of(RemoteMirror).to receive(:project).and_return(nil)
expect(remote_mirror.sync).to be_nil
end
end
end
context '#updated_since?' do context '#updated_since?' do
let(:remote_mirror) { create(:project, :remote_mirror).remote_mirrors.first } let(:remote_mirror) { create(:project, :remote_mirror).remote_mirrors.first }
let(:timestamp) { Time.now - 5.minutes } let(:timestamp) { Time.now - 5.minutes }
......
This diff is collapsed.
...@@ -28,7 +28,7 @@ describe RepositoryUpdateRemoteMirrorWorker do ...@@ -28,7 +28,7 @@ describe RepositoryUpdateRemoteMirrorWorker do
expect_any_instance_of(Projects::UpdateRemoteMirrorService).to receive(:execute).with(remote_mirror).and_return(status: :error, message: error_message) expect_any_instance_of(Projects::UpdateRemoteMirrorService).to receive(:execute).with(remote_mirror).and_return(status: :error, message: error_message)
expect do expect do
subject.perform(remote_mirror.id, Time.now) subject.perform(remote_mirror.id, Time.now)
end.to raise_error(RepositoryUpdateRemoteMirrorWorker::UpdateError, 'fail!') end.to raise_error(RepositoryUpdateRemoteMirrorWorker::UpdateError, error_message)
expect(remote_mirror.reload.update_status).to eq('failed') expect(remote_mirror.reload.update_status).to eq('failed')
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