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

Commit 356b3a5

Browse files
v3(services): Respect plan max_polling_duration when creating route bindings
[#174398273](https://www.pivotaltracker.com/story/show/174398273)
1 parent 6a3186a commit 356b3a5

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

app/jobs/v3/create_route_binding_job.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ def resource_type
3838
end
3939

4040
def perform
41-
precursor = RouteBinding.first(guid: @precursor_guid)
41+
precursor = route_binding
4242
gone! unless precursor
4343

4444
service_event_repository = VCAP::CloudController::Repositories::ServiceEventRepository::WithUserActor.new(@user_audit_info)
4545
action = V3::ServiceRouteBindingCreate.new(service_event_repository)
46+
compute_maximum_duration
4647

4748
if @first_time
4849
@first_time = false
@@ -67,6 +68,15 @@ def perform
6768

6869
private
6970

71+
def route_binding
72+
RouteBinding.first(guid: @precursor_guid)
73+
end
74+
75+
def compute_maximum_duration
76+
max_poll_duration_on_plan = route_binding.service_instance.service_plan.try(:maximum_polling_duration)
77+
self.maximum_duration_seconds = max_poll_duration_on_plan
78+
end
79+
7080
def gone!
7181
raise CloudController::Errors::ApiError.new_from_details('ResourceNotFound', "The binding could not be found: #{@precursor_guid}")
7282
end

spec/unit/jobs/v3/create_route_binding_job_spec.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module V3
99

1010
let(:space) { Space.make }
1111
let(:service_offering) { Service.make(requires: ['route_forwarding']) }
12-
let(:service_plan) { ServicePlan.make(service: service_offering) }
12+
let(:maximum_polling_duration) { nil }
13+
let(:service_plan) { ServicePlan.make(service: service_offering, maximum_polling_duration: maximum_polling_duration) }
1314
let(:service_instance) { ManagedServiceInstance.make(service_plan: service_plan, space: space) }
1415
let(:route) { Route.make(space: space) }
1516
let(:state) { 'in progress' }
@@ -66,6 +67,26 @@ module V3
6667
end
6768

6869
context 'asynchronous response' do
70+
context 'computes the maximum duration' do
71+
before do
72+
TestConfig.override({
73+
broker_client_max_async_poll_duration_minutes: 90009
74+
})
75+
subject.perform
76+
end
77+
78+
it 'sets to the default value' do
79+
expect(subject.maximum_duration_seconds).to eq(90009.minutes)
80+
end
81+
82+
context 'when the plan defines a duration' do
83+
let(:maximum_polling_duration) { 7465 }
84+
85+
it 'sets to the plan value' do
86+
expect(subject.maximum_duration_seconds).to eq(7465)
87+
end
88+
end
89+
end
6990
it 'calls bind and then poll' do
7091
subject.perform
7192

@@ -129,6 +150,27 @@ module V3
129150
expect(subject.finished).to be_truthy
130151
end
131152
end
153+
154+
context 'the maximum duration' do
155+
it 'recomputes the value' do
156+
subject.maximum_duration_seconds = 90009
157+
TestConfig.override({ broker_client_max_async_poll_duration_minutes: 8088 })
158+
subject.perform
159+
expect(subject.maximum_duration_seconds).to eq(8088.minutes)
160+
end
161+
162+
context 'when the plan value changes between calls' do
163+
before do
164+
subject.maximum_duration_seconds = 90009
165+
service_plan.update(maximum_polling_duration: 5000)
166+
subject.perform
167+
end
168+
169+
it 'sets to the new plan value' do
170+
expect(subject.maximum_duration_seconds).to eq(5000)
171+
end
172+
end
173+
end
132174
end
133175

134176
context 'retry interval' do

0 commit comments

Comments
 (0)