|
16 | 16 | body: client_body).to_return(status: broker_bind_status_code, body: bind_response_body) |
17 | 17 | end |
18 | 18 |
|
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 |
25 | 22 |
|
| 23 | + context 'should not be performed' do |
26 | 24 | 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 | + |
27 | 31 | [200, 201, 202].each do |code| |
28 | 32 | context "response is #{code}" do |
29 | 33 | let(:broker_bind_status_code) { code } |
|
48 | 52 | end |
49 | 53 | end |
50 | 54 |
|
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" }' } |
58 | 58 |
|
59 | 59 | it 'fails the job and does not perform orphan mitigation' do |
60 | 60 | execute_all_jobs(expected_successes: 0, expected_failures: 1) |
|
65 | 65 | end |
66 | 66 |
|
67 | 67 | 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| |
69 | 69 | context "response is #{code}" do |
70 | 70 | 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" }' } |
72 | 72 |
|
73 | 73 | it 'fails the job and updates the binding and job' do |
74 | 74 | execute_all_jobs(expected_successes: 0, expected_failures: 1) |
|
79 | 79 | end |
80 | 80 | end |
81 | 81 | 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 |
82 | 162 | end |
83 | 163 |
|
84 | 164 | 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 | + |
85 | 177 | context 'broker returns a 2xx code' do |
86 | 178 | [201, 202].each do |code| |
87 | 179 | context "response is #{code} with malformed response" do |
|
98 | 190 | end |
99 | 191 |
|
100 | 192 | [203, 204, 205, 206, 206, 208, 226].each do |code| |
101 | | - context "response is #{code}" do |
| 193 | + context "broker response is #{code}" do |
102 | 194 | let(:broker_bind_status_code) { code } |
103 | 195 | let(:bind_response_body) { '{}' } |
104 | 196 |
|
|
110 | 202 | end |
111 | 203 | end |
112 | 204 |
|
| 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 | + |
113 | 228 | context 'broker returns a 5xx code' do |
114 | 229 | Array(500..511).each do |code| |
115 | 230 | context "response is #{code}" do |
|
0 commit comments