diff options
author | Dylan Griffith <dyl.griffith@gmail.com> | 2018-02-20 12:42:05 +1100 |
---|---|---|
committer | Dylan Griffith <dyl.griffith@gmail.com> | 2018-02-20 12:47:07 +1100 |
commit | ba4114d25f538d198df2f681b9cb08567494207e (patch) | |
tree | 876cf5b44ab81b25cdf30acb9ebd642778800615 /spec/workers | |
parent | f0b27f9b406579a03e55fa16cbc7095009dc8c2b (diff) | |
download | gitlab-ce-ba4114d25f538d198df2f681b9cb08567494207e.tar.gz |
Refactor ingress IP address waiting code (#42643)
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb | 85 |
1 files changed, 80 insertions, 5 deletions
diff --git a/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb b/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb index 9f8bf35f604..aea924c6dd6 100644 --- a/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb +++ b/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb @@ -2,19 +2,94 @@ require 'spec_helper' describe ClusterWaitForIngressIpAddressWorker do describe '#perform' do - let(:service) { instance_double(Clusters::Applications::CheckIngressIpAddressService) } + let(:service) { instance_double(Clusters::Applications::CheckIngressIpAddressService, execute: true) } let(:application) { instance_double(Clusters::Applications::Ingress) } let(:worker) { described_class.new } - it 'finds the application and calls CheckIngressIpAddressService#execute' do - expect(worker).to receive(:find_application).with('ingress', 117).and_yield(application) - expect(Clusters::Applications::CheckIngressIpAddressService) + before do + allow(worker) + .to receive(:find_application) + .with('ingress', 117) + .and_yield(application) + + allow(Clusters::Applications::CheckIngressIpAddressService) .to receive(:new) .with(application) .and_return(service) - expect(service).to receive(:execute).with(2) + allow(described_class) + .to receive(:perform_in) + end + + it 'finds the application and calls CheckIngressIpAddressService#execute' do worker.perform('ingress', 117, 2) + + expect(service).to have_received(:execute) + end + + context 'when the service succeeds' do + it 'does not schedule another worker' do + worker.perform('ingress', 117, 2) + + expect(described_class) + .not_to have_received(:perform_in) + end + end + + context 'when the service fails' do + before do + allow(service) + .to receive(:execute) + .and_return(false) + end + + context 'when there are retries remaining' do + it 'schedules another worker with 1 less retry' do + worker.perform('ingress', 117, 2) + + expect(described_class) + .to have_received(:perform_in) + .with(ClusterWaitForIngressIpAddressWorker::INTERVAL, 'ingress', 117, 1) + end + end + + context 'when there are no retries_remaining' do + it 'does not schedule another worker' do + worker.perform('ingress', 117, 0) + + expect(described_class) + .not_to have_received(:perform_in) + end + end + end + + context 'when the update raises exception' do + before do + allow(service) + .to receive(:execute) + .and_raise(Clusters::Applications::CheckIngressIpAddressService::Error, "something went wrong") + end + + context 'when there are retries remaining' do + it 'schedules another worker with 1 less retry and re-raises the error' do + expect { worker.perform('ingress', 117, 2) } + .to raise_error(Clusters::Applications::CheckIngressIpAddressService::Error, "something went wrong") + + expect(described_class) + .to have_received(:perform_in) + .with(ClusterWaitForIngressIpAddressWorker::INTERVAL, 'ingress', 117, 1) + end + end + + context 'when there are no retries_remaining' do + it 'does not schedule another worker but re-raises the error' do + expect { worker.perform('ingress', 117, 0) } + .to raise_error(Clusters::Applications::CheckIngressIpAddressService::Error, "something went wrong") + + expect(described_class) + .not_to have_received(:perform_in) + end + end end end end |