diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-10-04 19:55:33 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-10-04 19:55:33 +0300 |
commit | e710e766b042ad0c74536416044ad0af2fdca012 (patch) | |
tree | 9b20836c96d68cb64ade01cfe9ecc95ca1cbe517 /spec/workers/wait_for_cluster_creation_worker_spec.rb | |
parent | 8d9d0f9401269a5718da9d22a1863a4c4ab5f36e (diff) |
fetch_gcp_operation_service_spec. finalize_cluster_creation_service_spec. wait_for_cluster_creation_worker_spec.
Diffstat (limited to 'spec/workers/wait_for_cluster_creation_worker_spec.rb')
-rw-r--r-- | spec/workers/wait_for_cluster_creation_worker_spec.rb | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/spec/workers/wait_for_cluster_creation_worker_spec.rb b/spec/workers/wait_for_cluster_creation_worker_spec.rb index 753c7efb9af..eed6bec00f8 100644 --- a/spec/workers/wait_for_cluster_creation_worker_spec.rb +++ b/spec/workers/wait_for_cluster_creation_worker_spec.rb @@ -4,14 +4,54 @@ describe WaitForClusterCreationWorker do describe '#perform' do context 'when cluster exists' do let(:cluster) { create(:gcp_cluster) } + let(:operation) { double } - it 'fetches gcp operation status' do - expect_any_instance_of(Ci::FetchGcpOperationService).to receive(:execute) + before do + allow(operation).to receive(:status).and_return(status) + allow(operation).to receive(:start_time).and_return(1.minutes.ago) + allow(operation).to receive(:status_message).and_return('error') + allow_any_instance_of(Ci::FetchGcpOperationService).to receive(:execute).and_yield(operation) + end + + context 'when operation status is RUNNING' do + let(:status) { 'RUNNING' } + + it 'reschedules worker' do + expect(WaitForClusterCreationWorker).to receive(:perform_in) - described_class.new.perform(cluster.id) + described_class.new.perform(cluster.id) + end + + context 'when operation timeout' do + before do + allow(operation).to receive(:start_time).and_return(30.minutes.ago) + end + + it 'sets an error message on cluster' do + described_class.new.perform(cluster.id) + expect(cluster.reload).to be_errored + end + end end - # TODO: context 'when operation.status is runnning' + context 'when operation status is DONE' do + let(:status) { 'DONE' } + + it 'finalizes cluster creation' do + expect_any_instance_of(Ci::FinalizeClusterCreationService).to receive(:execute) + + described_class.new.perform(cluster.id) + end + end + + context 'when operation status is others' do + let(:status) { 'others' } + + it 'sets an error message on cluster' do + described_class.new.perform(cluster.id) + expect(cluster.reload).to be_errored + end + end end context 'when cluster does not exist' do |