|
250 | 250 | end |
251 | 251 | end |
252 | 252 |
|
| 253 | + context 'when the response_to does not match the request_id' do |
| 254 | + |
| 255 | + let(:documents) do |
| 256 | + [{ 'name' => 'bob' }, { 'name' => 'alice' }] |
| 257 | + end |
| 258 | + |
| 259 | + let(:insert) do |
| 260 | + Mongo::Protocol::Insert.new(TEST_DB, TEST_COLL, documents) |
| 261 | + end |
| 262 | + |
| 263 | + let(:query_bob) do |
| 264 | + Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'bob' }) |
| 265 | + end |
| 266 | + |
| 267 | + let(:query_alice) do |
| 268 | + Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'alice' }) |
| 269 | + end |
| 270 | + |
| 271 | + after do |
| 272 | + authorized_collection.delete_many |
| 273 | + end |
| 274 | + |
| 275 | + before do |
| 276 | + # Fake a query for which we did not read the response. See RUBY-1117 |
| 277 | + allow(query_bob).to receive(:replyable?) { false } |
| 278 | + connection.dispatch([ insert, query_bob ]) |
| 279 | + end |
| 280 | + |
| 281 | + it 'raises an UnexpectedResponse' do |
| 282 | + expect { |
| 283 | + connection.dispatch([ query_alice ]) |
| 284 | + }.to raise_error(Mongo::Error::UnexpectedResponse, |
| 285 | + /Got response for request ID \d+ but expected response for request ID \d+/) |
| 286 | + end |
| 287 | + |
| 288 | + it "doesn't break subsequent requests" do |
| 289 | + expect { |
| 290 | + connection.dispatch([ query_alice ]) |
| 291 | + }.to raise_error(Mongo::Error::UnexpectedResponse) |
| 292 | + |
| 293 | + expect(connection.dispatch([ query_alice ]).documents.first['name']).to eq('alice') |
| 294 | + end |
| 295 | + end |
| 296 | + |
| 297 | + context 'when a request is brutaly interrupted (Thread.kill)' do |
| 298 | + |
| 299 | + let(:documents) do |
| 300 | + [{ 'name' => 'bob' }, { 'name' => 'alice' }] |
| 301 | + end |
| 302 | + |
| 303 | + let(:insert) do |
| 304 | + Mongo::Protocol::Insert.new(TEST_DB, TEST_COLL, documents) |
| 305 | + end |
| 306 | + |
| 307 | + let(:query_bob) do |
| 308 | + Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'bob' }) |
| 309 | + end |
| 310 | + |
| 311 | + let(:query_alice) do |
| 312 | + Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'alice' }) |
| 313 | + end |
| 314 | + |
| 315 | + before do |
| 316 | + connection.dispatch([ insert ]) |
| 317 | + end |
| 318 | + |
| 319 | + after do |
| 320 | + authorized_collection.delete_many |
| 321 | + end |
| 322 | + |
| 323 | + it "closes the socket and does not use it for subsequent requests" do |
| 324 | + t = Thread.new { |
| 325 | + # Kill the thread just before the reply is read |
| 326 | + allow(Mongo::Protocol::Reply).to receive(:deserialize_header) { t.kill } |
| 327 | + connection.dispatch([ query_bob ]) |
| 328 | + } |
| 329 | + t.join |
| 330 | + allow(Mongo::Protocol::Reply).to receive(:deserialize_header).and_call_original |
| 331 | + expect(connection.dispatch([ query_alice ]).documents.first['name']).to eq('alice') |
| 332 | + end |
| 333 | + end |
| 334 | + |
| 335 | + |
253 | 336 | context 'when the message exceeds the max size' do |
254 | 337 |
|
255 | 338 | context 'when the message is an insert' do |
|
0 commit comments