Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4695

Fix test event loop policy and improve error traceback for ClientBulkWriteException

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.9
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Context

      See https://spruce.mongodb.com/task/mongo_python_driver_tests_windows_python_version__platform~windows_64_vsMulti_small_auth_ssl~auth_ssl_python_version_windows~3.8_test_8.0_sharded_cluster_d6b896d18b3cb351148b2dfac0b1e5c062a18169_24_08_21_21_52_16/tests?execution=0&sortBy=STATUS&sortDir=ASC for failure.

      test.test_client_bulk_write.TestClientBulkWriteCSOT.test_timeout_in_multi_batch_bulk_write

      Definition of done

      In PYTHON-4692 we applied a skip, but we should address this error:

       [2024/08/22 08:03:32.279] FAILURE: AssertionError: TimeoutError() is not an instance of <class 'pymongo.errors.NetworkTimeout'> ()
       [2024/08/22 08:03:32.279] self = <test.asynchronous.test_client_bulk_write.TestClientBulkWriteCSOT testMethod=test_timeout_in_multi_batch_bulk_write>
       [2024/08/22 08:03:32.279]     @async_client_context.require_version_min(8, 0, 0, -24)
       [2024/08/22 08:03:32.279]     @async_client_context.require_failCommand_fail_point
       [2024/08/22 08:03:32.279]     async def test_timeout_in_multi_batch_bulk_write(self):
       [2024/08/22 08:03:32.279]         _OVERHEAD = 500
       [2024/08/22 08:03:32.279]     
       [2024/08/22 08:03:32.279]         internal_client = await async_rs_or_single_client(timeoutMS=None)
       [2024/08/22 08:03:32.279]         self.addAsyncCleanup(internal_client.close)
       [2024/08/22 08:03:32.279]     
       [2024/08/22 08:03:32.279]         collection = internal_client.db["coll"]
       [2024/08/22 08:03:32.279]         self.addAsyncCleanup(collection.drop)
       [2024/08/22 08:03:32.279]         await collection.drop()
       [2024/08/22 08:03:32.279]     
       [2024/08/22 08:03:32.279]         fail_command = {
       [2024/08/22 08:03:32.279]             "configureFailPoint": "failCommand",
       [2024/08/22 08:03:32.279]             "mode": {"times": 2},
       [2024/08/22 08:03:32.279]             "data": {"failCommands": ["bulkWrite"], "blockConnection": True, "blockTimeMS": 1010},
       [2024/08/22 08:03:32.279]         }
       [2024/08/22 08:03:32.279]         async with self.fail_point(fail_command):
       [2024/08/22 08:03:32.279]             models = []
       [2024/08/22 08:03:32.279]             num_models = int(self.max_message_size_bytes / self.max_bson_object_size + 1)
       [2024/08/22 08:03:32.279]             b_repeated = "b" * (self.max_bson_object_size - _OVERHEAD)
       [2024/08/22 08:03:32.279]             for _ in range(num_models):
       [2024/08/22 08:03:32.279]                 models.append(
       [2024/08/22 08:03:32.279]                     InsertOne(
       [2024/08/22 08:03:32.279]                         namespace="db.coll",
       [2024/08/22 08:03:32.279]                         document={"a": b_repeated},
       [2024/08/22 08:03:32.279]                     )
       [2024/08/22 08:03:32.279]                 )
       [2024/08/22 08:03:32.279]     
       [2024/08/22 08:03:32.279]             listener = OvertCommandListener()
       [2024/08/22 08:03:32.279]             client = await async_rs_or_single_client(
       [2024/08/22 08:03:32.279]                 event_listeners=[listener],
       [2024/08/22 08:03:32.279]                 readConcernLevel="majority",
       [2024/08/22 08:03:32.279]                 readPreference="primary",
       [2024/08/22 08:03:32.279]                 timeoutMS=2000,
       [2024/08/22 08:03:32.279]                 w="majority",
       [2024/08/22 08:03:32.279]             )
       [2024/08/22 08:03:32.279]             self.addAsyncCleanup(client.close)
       [2024/08/22 08:03:32.279]             await client.admin.command("ping")  # Init the client first.
       [2024/08/22 08:03:32.279]             with self.assertRaises(ClientBulkWriteException) as context:
       [2024/08/22 08:03:32.279]                 await client.bulk_write(models=models)
       [2024/08/22 08:03:32.279] >           self.assertIsInstance(context.exception.error, NetworkTimeout)
       [2024/08/22 08:03:32.279] E           AssertionError: TimeoutError() is not an instance of <class 'pymongo.errors.NetworkTimeout'>
       [2024/08/22 08:03:32.279] test\asynchronous\test_client_bulk_write.py:599: AssertionError
      

      PyMongo shouldn't be raising a TimeOutError. I can reproduce the error on a Windows EVG host with AUTH=auth TOPOLOGY=sharded_cluster MONGODB_VERSION=8.0.

      Pitfalls

      None

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: