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

Commit 42a3bcd

Browse files
v3(tests): Enhanced Bindings Orphan mitigation tests
[#174878594](https://www.pivotaltracker.com/story/show/174878594)
1 parent b7f97a4 commit 42a3bcd

2 files changed

Lines changed: 155 additions & 40 deletions

File tree

spec/request/service_route_bindings_spec.rb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -686,30 +686,6 @@
686686
'request' => request.with_indifferent_access
687687
})
688688
end
689-
690-
context 'orphan mitigation' do
691-
it_behaves_like 'create binding orphan mitigation' do
692-
let(:bind_url) { broker_bind_url }
693-
let(:plan_id) { plan.unique_id }
694-
let(:offering_id) { offering.unique_id }
695-
let(:client_body) do
696-
{
697-
context: {
698-
platform: 'cloudfoundry',
699-
organization_guid: org.guid,
700-
organization_name: org.name,
701-
space_guid: space.guid,
702-
space_name: space.name,
703-
},
704-
service_id: service_instance.service_plan.service.unique_id,
705-
plan_id: service_instance.service_plan.unique_id,
706-
bind_resource: {
707-
route: route.uri,
708-
},
709-
}
710-
end
711-
end
712-
end
713689
end
714690

715691
context 'when the binding completes asynchronously' do
@@ -860,6 +836,30 @@
860836
end
861837
end
862838
end
839+
840+
context 'orphan mitigation' do
841+
it_behaves_like 'create binding orphan mitigation' do
842+
let(:bind_url) { broker_bind_url }
843+
let(:plan_id) { plan.unique_id }
844+
let(:offering_id) { offering.unique_id }
845+
let(:client_body) do
846+
{
847+
context: {
848+
platform: 'cloudfoundry',
849+
organization_guid: org.guid,
850+
organization_name: org.name,
851+
space_guid: space.guid,
852+
space_name: space.name,
853+
},
854+
service_id: service_instance.service_plan.service.unique_id,
855+
plan_id: service_instance.service_plan.unique_id,
856+
bind_resource: {
857+
route: route.uri,
858+
},
859+
}
860+
end
861+
end
862+
end
863863
end
864864

865865
describe 'permissions' do

spec/support/shared_examples/request/bindings_orphan_mitigation.rb

Lines changed: 131 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
body: client_body).to_return(status: broker_bind_status_code, body: bind_response_body)
1717
end
1818

19-
context 'should not be performed' do
20-
before do
21-
stub_request(:get, "#{bind_url}/last_operation").
22-
with({ query: { plan_id: plan_id, service_id: offering_id } }).
23-
to_return(status: 200, body: '{"state": "in progress"}')
24-
end
19+
after do
20+
WebMock.reset!
21+
end
2522

23+
context 'should not be performed' do
2624
context 'broker returns valid 200, 201, 202' do
25+
before do
26+
stub_request(:get, "#{bind_url}/last_operation").
27+
with({ query: { plan_id: plan_id, service_id: offering_id } }).
28+
to_return(status: 200, body: '{}')
29+
end
30+
2731
[200, 201, 202].each do |code|
2832
context "response is #{code}" do
2933
let(:broker_bind_status_code) { code }
@@ -48,13 +52,9 @@
4852
end
4953
end
5054

51-
context 'response for last operation is 200 state failed' do
52-
let(:broker_bind_status_code) { 202 }
53-
before do
54-
stub_request(:get, "#{bind_url}/last_operation").
55-
with({ query: { plan_id: plan_id, service_id: offering_id } }).
56-
to_return(status: 200, body: '{"state": "failed"}')
57-
end
55+
context 'response is 422 with known reason' do
56+
let(:broker_bind_status_code) { 422 }
57+
let(:bind_response_body) { '{ "error": "ConcurrencyError", "description": "some description" }' }
5858

5959
it 'fails the job and does not perform orphan mitigation' do
6060
execute_all_jobs(expected_successes: 0, expected_failures: 1)
@@ -65,10 +65,10 @@
6565
end
6666

6767
context 'broker returns a 4xx code' do
68-
[400, 401, 408, 409, *411..431].each do |code|
68+
[400, 401, 408, 409, *411..421, *423..431].each do |code|
6969
context "response is #{code}" do
7070
let(:broker_bind_status_code) { code }
71-
let(:bind_response_body) { '{ "error": "ConcurrencyError", "description": "some description" }' }
71+
let(:bind_response_body) { '{ "error": "some 4xx error", "description": "some description" }' }
7272

7373
it 'fails the job and updates the binding and job' do
7474
execute_all_jobs(expected_successes: 0, expected_failures: 1)
@@ -79,9 +79,101 @@
7979
end
8080
end
8181
end
82+
83+
84+
context 'last operation' do
85+
context 'response for last operation is 200 state failed' do
86+
let(:broker_bind_status_code) { 202 }
87+
before do
88+
stub_request(:get, "#{bind_url}/last_operation").
89+
with({ query: { plan_id: plan_id, service_id: offering_id } }).
90+
to_return(status: 200, body: '{"state": "failed"}')
91+
end
92+
93+
it 'fails the job and does not perform orphan mitigation' do
94+
execute_all_jobs(expected_successes: 0, expected_failures: 1)
95+
96+
assert_failed_job(binding, job)
97+
assert_no_orphan_mitigation_performed(plan_id, offering_id)
98+
end
99+
end
100+
101+
context 'response for last operation is 200 with a malformed response' do
102+
let(:broker_bind_status_code) { 202 }
103+
before do
104+
stub_request(:get, "#{bind_url}/last_operation").
105+
with({ query: { plan_id: plan_id, service_id: offering_id } }).
106+
to_return(status: 200, body: 'this is not json')
107+
end
108+
109+
it 'fails the job and does not perform orphan mitigation' do
110+
execute_all_jobs(expected_successes: 1, expected_failures: 0)
111+
112+
assert_no_orphan_mitigation_performed(plan_id, offering_id)
113+
end
114+
end
115+
116+
context 'response for last operation is 410' do
117+
let(:broker_bind_status_code) { 202 }
118+
119+
before do
120+
stub_request(:get, "#{bind_url}/last_operation").
121+
with({ query: { plan_id: plan_id, service_id: offering_id } }).
122+
to_return(status: 410, body: '{}')
123+
end
124+
125+
it 'retries and does not perform orphan mitigation' do
126+
execute_all_jobs(expected_successes: 1, expected_failures: 0)
127+
128+
assert_no_orphan_mitigation_performed(plan_id, offering_id)
129+
end
130+
end
131+
132+
context 'response for last operation is 404' do
133+
let(:broker_bind_status_code) { 202 }
134+
before do
135+
stub_request(:get, "#{bind_url}/last_operation").
136+
with({ query: { plan_id: plan_id, service_id: offering_id } }).
137+
to_return(status: 404, body: '{}')
138+
end
139+
140+
it 'retries and does not perform orphan mitigation' do
141+
execute_all_jobs(expected_successes: 1, expected_failures: 0)
142+
143+
assert_no_orphan_mitigation_performed(plan_id, offering_id)
144+
end
145+
end
146+
147+
context 'response for last operation is 400' do
148+
let(:broker_bind_status_code) { 202 }
149+
before do
150+
stub_request(:get, "#{bind_url}/last_operation").
151+
with({ query: { plan_id: plan_id, service_id: offering_id } }).
152+
to_return(status: 400, body: '{}')
153+
end
154+
155+
it 'retries and does not perform orphan mitigation' do
156+
execute_all_jobs(expected_successes: 0, expected_failures: 1)
157+
158+
assert_no_orphan_mitigation_performed(plan_id, offering_id)
159+
end
160+
end
161+
end
82162
end
83163

84164
context 'should be performed' do
165+
context 'broker returns 200 with bad data' do
166+
let(:broker_bind_status_code) { 200 }
167+
let(:bind_response_body) { '{ "route_service_url": "bad-url"}' }
168+
169+
it 'fails the job and performs OM' do
170+
execute_all_jobs(expected_successes: 1, expected_failures: 1)
171+
172+
assert_failed_job(binding, job)
173+
assert_orphan_mitigation_performed(plan_id, offering_id)
174+
end
175+
end
176+
85177
context 'broker returns a 2xx code' do
86178
[201, 202].each do |code|
87179
context "response is #{code} with malformed response" do
@@ -98,7 +190,7 @@
98190
end
99191

100192
[203, 204, 205, 206, 206, 208, 226].each do |code|
101-
context "response is #{code}" do
193+
context "broker response is #{code}" do
102194
let(:broker_bind_status_code) { code }
103195
let(:bind_response_body) { '{}' }
104196

@@ -110,6 +202,29 @@
110202
end
111203
end
112204

205+
context 'broker returns a 410 code' do
206+
let(:broker_bind_status_code) { 410 }
207+
208+
it 'does orphan mitigation and fails the job' do
209+
execute_all_jobs(expected_successes: 1, expected_failures: 1)
210+
211+
assert_failed_job(binding, job)
212+
assert_orphan_mitigation_performed(plan_id, offering_id)
213+
end
214+
end
215+
216+
context 'broker response is 422 with unknown reason' do
217+
let(:broker_bind_status_code) { 422 }
218+
let(:bind_response_body) { '{ "error": "some random unprocessable entity", "description": "some description" }' }
219+
220+
it 'fails the job and performs orphan mitigation' do
221+
execute_all_jobs(expected_successes: 1, expected_failures: 1)
222+
223+
assert_failed_job(binding, job)
224+
assert_orphan_mitigation_performed(plan_id, offering_id)
225+
end
226+
end
227+
113228
context 'broker returns a 5xx code' do
114229
Array(500..511).each do |code|
115230
context "response is #{code}" do

0 commit comments

Comments
 (0)