MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_operation_failure

Method test_operation_failure

test/test_client.py:1507–1525  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1505 signal.signal(signal.SIGALRM, old_signal_handler)
1506
1507 def test_operation_failure(self):
1508 # Ensure MongoClient doesn't close socket after it gets an error
1509 # response to getLastError. PYTHON-395. We need a new client here
1510 # to avoid race conditions caused by replica set failover or idle
1511 # socket reaping.
1512 client = self.single_client()
1513 client.pymongo_test.test.find_one()
1514 pool = get_pool(client)
1515 socket_count = len(pool.conns)
1516 self.assertGreaterEqual(socket_count, 1)
1517 old_conn = next(iter(pool.conns))
1518 client.pymongo_test.test.drop()
1519 client.pymongo_test.test.insert_one({"_id": "foo"})
1520 with self.assertRaises(OperationFailure):
1521 client.pymongo_test.test.insert_one({"_id": "foo"})
1522
1523 self.assertEqual(socket_count, len(pool.conns))
1524 new_con = next(iter(pool.conns))
1525 self.assertEqual(old_conn, new_con)
1526
1527 def test_lazy_connect_w0(self):
1528 # Ensure that connect-on-demand works when the first operation is

Callers

nothing calls this directly

Calls 7

get_poolFunction · 0.90
nextFunction · 0.90
iterFunction · 0.85
single_clientMethod · 0.80
find_oneMethod · 0.45
dropMethod · 0.45
insert_oneMethod · 0.45

Tested by

no test coverage detected