diff --git a/tests/integration/container/conftest.py b/tests/integration/container/conftest.py index 53c73c6f..cc42d7cc 100644 --- a/tests/integration/container/conftest.py +++ b/tests/integration/container/conftest.py @@ -109,7 +109,12 @@ def pytest_runtest_setup(item): logger.warning("conftest.ExceptionWhileObtainingInstanceIDs", ex) instances = list() - sleep(5) + # Only sleep if condition is still not met + if (len(instances) < request.get_num_of_instances() + or len(instances) == 0 + or not rds_utility.is_db_instance_writer(instances[0])) and ( + timeit.default_timer() - start_time) < 300: + sleep(5) assert len(instances) > 0 current_writer = instances[0] @@ -144,6 +149,7 @@ def pytest_runtest_setup(item): MonitoringThreadContainer.clean_up() ThreadPoolContainer.release_resources(wait=True) + ConnectionProviderManager.release_resources() ConnectionProviderManager.reset_provider() DatabaseDialectManager.reset_custom_dialect() DriverDialectManager.reset_custom_dialect() diff --git a/tests/integration/container/test_read_write_splitting.py b/tests/integration/container/test_read_write_splitting.py index 24a6e485..6d2a93b5 100644 --- a/tests/integration/container/test_read_write_splitting.py +++ b/tests/integration/container/test_read_write_splitting.py @@ -81,6 +81,11 @@ def clear_caches(self): RdsHostListProvider._topology_cache.clear() RdsHostListProvider._is_primary_cluster_id_cache.clear() RdsHostListProvider._cluster_ids_to_update.clear() + yield + ConnectionProviderManager.release_resources() + ConnectionProviderManager.reset_provider() + gc.collect() + ProxyHelper.enable_all_connectivity() @pytest.fixture def props(self, plugin_config, conn_utils): @@ -196,14 +201,6 @@ def proxied_failover_props(self, failover_props, plugin_config, conn_utils): ) return props_copy - @pytest.fixture(autouse=True) - def cleanup_connection_provider(self): - yield - ConnectionProviderManager.release_resources() - ConnectionProviderManager.reset_provider() - gc.collect() - ProxyHelper.enable_all_connectivity() - def test_connect_to_writer__switch_read_only( self, test_driver: TestDriver, props, conn_utils, rds_utils ): diff --git a/tests/test_weight_random_host_selector.py b/tests/unit/test_weight_random_host_selector.py similarity index 100% rename from tests/test_weight_random_host_selector.py rename to tests/unit/test_weight_random_host_selector.py