Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit dc1c82f

Browse files
committed
v3 msi create - Respect plan max_polling_duration
[#171649898](https://www.pivotaltracker.com/story/show/171649898)
1 parent 2483d0f commit dc1c82f

5 files changed

Lines changed: 97 additions & 82 deletions
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
RSpec.shared_examples 'end_timestamp' do
2+
let(:cc_config_max_polling_duration) { 10080 }
3+
4+
before do
5+
config_override = {
6+
broker_client_max_async_poll_duration_minutes: cc_config_max_polling_duration,
7+
}
8+
TestConfig.override(config_override)
9+
end
10+
11+
context 'when the job is new' do
12+
context 'when the plan does not define a max_polling_duration' do
13+
it 'adds the broker_client_max_async_poll_duration_minutes to the current time' do
14+
now = Time.now
15+
expected_end_timestamp = now + cc_config_max_polling_duration.minutes
16+
Timecop.freeze now do
17+
expect(job.end_timestamp).to be_within(0.01).of(expected_end_timestamp)
18+
end
19+
end
20+
end
21+
22+
context 'when the plan defines a max_polling duration' do
23+
let(:plan_maximum_polling_duration) {}
24+
25+
before do
26+
service_plan.maximum_polling_duration = plan_maximum_polling_duration
27+
service_plan.save
28+
end
29+
30+
context 'the plan max_polling_duration is shorter than the platform config' do
31+
let(:plan_maximum_polling_duration) { 360 } # in seconds
32+
33+
it 'adds the plan max_polling_duration to the current time' do
34+
now = Time.now
35+
expected_end_timestamp = now + plan_maximum_polling_duration.seconds
36+
37+
Timecop.freeze now do
38+
expect(job.end_timestamp).to be_within(0.01).of(expected_end_timestamp)
39+
end
40+
end
41+
end
42+
43+
context 'the plan max_polling_duration is longer than the platform config' do
44+
let(:plan_maximum_polling_duration) { 36000000 } # in seconds
45+
46+
it 'adds the broker_client_max_async_poll_duration_minutes to the current time' do
47+
now = Time.now
48+
expected_end_timestamp = now + cc_config_max_polling_duration.minutes
49+
Timecop.freeze now do
50+
expect(job.end_timestamp).to be_within(0.01).of(expected_end_timestamp)
51+
end
52+
end
53+
end
54+
55+
context 'when there is a database error in fetching the plan' do
56+
it 'should set end_timestamp to config value' do
57+
allow(VCAP::CloudController::ManagedServiceInstance).to receive(:first) do |e|
58+
raise Sequel::Error.new(e)
59+
end
60+
Timecop.freeze(Time.now)
61+
expect(job.end_timestamp).to eq(Time.now + cc_config_max_polling_duration.minutes)
62+
end
63+
end
64+
end
65+
end
66+
67+
context 'when the job is fetched from the database' do
68+
it 'returns the previously computed and persisted end_timestamp' do
69+
now = Time.now
70+
expected_end_timestamp = now + cc_config_max_polling_duration.minutes
71+
72+
job_id = nil
73+
Timecop.freeze now do
74+
enqueued_job = VCAP::CloudController::Jobs::Enqueuer.new(
75+
job,
76+
queue: VCAP::CloudController::Jobs::Queues.generic,
77+
run_at: Time.now).enqueue
78+
job_id = enqueued_job.id
79+
end
80+
81+
Timecop.freeze(now + 1.day) do
82+
rehydrated_job = Delayed::Job.first(id: job_id).payload_object.handler.handler
83+
expect(rehydrated_job.end_timestamp).to be_within(0.01).of(expected_end_timestamp)
84+
end
85+
end
86+
end
87+
end

spec/unit/jobs/v3/create_service_instance_job_spec.rb renamed to spec/unit/jobs/v3/services/create_service_instance_job_spec.rb

File renamed without changes.

spec/unit/jobs/v3/services/fetch_last_operation_job_spec.rb

Lines changed: 10 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
require 'spec_helper'
22
require 'jobs/v3/services/fetch_last_operation_job'
33
require_relative '../../services/shared/when_broker_returns_retry_after_header'
4+
require_relative 'async_operation_end_timestamp'
45

56
module VCAP::CloudController
67
module V3
78
RSpec.describe FetchLastOperationJob, job_context: :worker do
89
let(:proposed_service_plan) { ServicePlan.make }
910
let(:proposed_maintenance_info) { { 'version' => '2.0' } }
10-
let(:maximum_polling_duration_for_plan) {}
11-
let(:service_plan) { ServicePlan.make(maximum_polling_duration: maximum_polling_duration_for_plan) }
11+
let(:service_plan) { ServicePlan.make }
1212
let(:service_instance) do
1313
operation = ServiceInstanceOperation.make(proposed_changes: {
1414
name: 'new-fake-name',
@@ -39,7 +39,6 @@ module V3
3939
description: description
4040
}
4141
end
42-
let(:max_duration) { 10080 }
4342
let(:request_attrs) do
4443
{
4544
dummy_data: 'dummy_data'
@@ -77,61 +76,21 @@ def run_job(job, successes: 1, failures: 0)
7776
end
7877

7978
describe '#initialize' do
80-
let(:default_polling_interval) { 120 }
81-
let(:max_duration) { 10080 }
82-
83-
before do
84-
config_override = {
85-
broker_client_default_async_poll_interval_seconds: default_polling_interval,
86-
broker_client_max_async_poll_duration_minutes: max_duration,
87-
}
88-
TestConfig.override(config_override)
89-
end
90-
91-
context 'when the caller does not provide the maximum number of attempts' do
92-
it 'should the default configuration value' do
93-
Timecop.freeze(Time.now)
94-
expect(job.end_timestamp).to eq(Time.now + max_duration.minutes)
95-
end
96-
end
97-
9879
context 'when the default poll interval is greater than the max value (24 hours)' do
9980
let(:default_polling_interval) { 24.hours + 1.minute }
81+
before do
82+
config_override = {
83+
broker_client_default_async_poll_interval_seconds: default_polling_interval,
84+
}
85+
TestConfig.override(config_override)
86+
end
10087

10188
it 'enqueues the job using the maximum polling interval' do
10289
expect(job.poll_interval).to eq 24.hours
10390
end
10491
end
10592

106-
context 'when the service plan has maximum_polling_duration' do
107-
let(:maximum_polling_duration_for_plan) { 36000000 } # in seconds
108-
109-
context "when the config value is smaller than plan's maximum_polling_duration" do
110-
let(:max_duration) { 10 } # in minutes
111-
it 'should set end_timestamp to config value' do
112-
Timecop.freeze(Time.now)
113-
expect(job.end_timestamp).to eq(Time.now + max_duration.minutes)
114-
end
115-
end
116-
117-
context "when the config value is greater than plan's maximum_polling_duration" do
118-
let(:max_duration) { 1068367346 } # in minutes
119-
it "should set end_timestamp to the plan's maximum_polling_duration value" do
120-
Timecop.freeze(Time.now)
121-
expect(job.end_timestamp).to eq(Time.now + maximum_polling_duration_for_plan.seconds)
122-
end
123-
end
124-
end
125-
126-
context 'when there is a database error in fetching the plan' do
127-
it 'should set end_timestamp to config value' do
128-
allow(ManagedServiceInstance).to receive(:first) do |e|
129-
raise Sequel::Error.new(e)
130-
end
131-
Timecop.freeze(Time.now)
132-
expect(job.end_timestamp).to eq(Time.now + max_duration.minutes)
133-
end
134-
end
93+
include_context 'end_timestamp'
13594
end
13695

13796
describe '#perform' do
@@ -320,6 +279,7 @@ def run_job(job, successes: 1, failures: 0)
320279

321280
context 'when the job has fetched for more than the max poll duration' do
322281
let(:state) { 'in progress' }
282+
let(:max_duration) { 10080 }
323283

324284
before do
325285
run_job(job)
@@ -473,38 +433,6 @@ def run_job(job, successes: 1, failures: 0)
473433
end
474434
end
475435

476-
describe '#end_timestamp' do
477-
let(:max_poll_duration) { VCAP::CloudController::Config.config.get(:broker_client_max_async_poll_duration_minutes) }
478-
479-
context 'when the job is new' do
480-
it 'adds the broker_client_max_async_poll_duration_minutes to the current time' do
481-
now = Time.now
482-
expected_end_timestamp = now + max_poll_duration.minutes
483-
Timecop.freeze now do
484-
expect(job.end_timestamp).to be_within(0.01).of(expected_end_timestamp)
485-
end
486-
end
487-
end
488-
489-
context 'when the job is fetched from the database' do
490-
it 'returns the previously computed and persisted end_timestamp' do
491-
now = Time.now
492-
expected_end_timestamp = now + max_poll_duration.minutes
493-
494-
job_id = nil
495-
Timecop.freeze now do
496-
enqueued_job = Jobs::Enqueuer.new(job, queue: Jobs::Queues.generic, run_at: Time.now).enqueue
497-
job_id = enqueued_job.id
498-
end
499-
500-
Timecop.freeze(now + 1.day) do
501-
rehydrated_job = Delayed::Job.first(id: job_id).payload_object.handler.handler
502-
expect(rehydrated_job.end_timestamp).to be_within(0.01).of(expected_end_timestamp)
503-
end
504-
end
505-
end
506-
end
507-
508436
pending('not yet ready') do
509437
context 'when all operations succeed and the state is `succeeded`' do
510438
let(:state) { 'succeeded' }

spec/unit/jobs/v3/synchronize_broker_catalog_job_spec.rb renamed to spec/unit/jobs/v3/services/synchronize_broker_catalog_job_spec.rb

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)