Skip to content

Commit 2df8d33

Browse files
authored
test: re-enable efm2 integration test cases (#1050)
1 parent 3d1d530 commit 2df8d33

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

tests/integration/container/test_aurora_failover.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
from __future__ import annotations
1616

17+
import gc
1718
from time import sleep
1819
from typing import TYPE_CHECKING, List
1920

2021
import pytest
2122

2223
from aws_advanced_python_wrapper.errors import (
2324
FailoverSuccessError, TransactionResolutionUnknownError)
25+
from aws_advanced_python_wrapper.host_monitoring_plugin import \
26+
MonitoringThreadContainer
2427
from aws_advanced_python_wrapper.utils.properties import (Properties,
2528
WrapperProperties)
2629
from .utils.conditions import (disable_on_features, enable_on_deployments,
@@ -56,6 +59,8 @@ def setup_method(self, request):
5659
self.logger.info(f"Starting test: {request.node.name}")
5760
yield
5861
self.logger.info(f"Ending test: {request.node.name}")
62+
MonitoringThreadContainer.clean_up()
63+
gc.collect()
5964

6065
@pytest.fixture(scope='class')
6166
def aurora_utility(self):
@@ -132,6 +137,7 @@ def test_fail_from_writer_to_new_writer_fail_on_connection_bound_object_invocati
132137
assert aurora_utility.is_db_instance_writer(current_connection_id) is True
133138
assert current_connection_id != initial_writer_id
134139

140+
@pytest.mark.parametrize("plugins", ["failover,host_monitoring", "failover,host_monitoring_v2"])
135141
@enable_on_features([TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED,
136142
TestEnvironmentFeatures.ABORT_CONNECTION_SUPPORTED])
137143
def test_fail_from_reader_to_writer(
@@ -140,12 +146,13 @@ def test_fail_from_reader_to_writer(
140146
test_driver: TestDriver,
141147
conn_utils,
142148
proxied_props,
143-
aurora_utility):
149+
aurora_utility,
150+
plugins):
144151
target_driver_connect = DriverHelper.get_connect_func(test_driver)
145152
reader: TestInstanceInfo = test_environment.get_proxy_instances()[1]
146153
writer_id: str = test_environment.get_proxy_writer().get_instance_id()
147154

148-
proxied_props["plugins"] = "failover,host_monitoring"
155+
proxied_props["plugins"] = plugins
149156
with AwsWrapperConnection.connect(
150157
target_driver_connect,
151158
**conn_utils.get_proxy_connect_params(reader.get_host()),

tests/integration/container/test_basic_connectivity.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
from typing import TYPE_CHECKING
1818

19+
from aws_advanced_python_wrapper.host_monitoring_plugin import \
20+
MonitoringThreadContainer
21+
1922
if TYPE_CHECKING:
2023
from .utils.test_instance_info import TestInstanceInfo
2124
from .utils.test_driver import TestDriver
@@ -126,12 +129,13 @@ def test_proxied_wrapper_connection_failed(
126129
# That is expected exception. Test pass.
127130
assert True
128131

132+
@pytest.mark.parametrize("plugins", ["failover,host_monitoring", "failover,host_monitoring_v2"])
129133
@enable_on_num_instances(min_instances=2)
130134
@enable_on_deployments([DatabaseEngineDeployment.AURORA, DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER])
131135
@enable_on_features([TestEnvironmentFeatures.ABORT_CONNECTION_SUPPORTED])
132136
def test_wrapper_connection_reader_cluster_with_efm_enabled(self, test_driver: TestDriver, conn_utils, plugins):
133137
props: Properties = Properties({
134-
WrapperProperties.PLUGINS.name: "host_monitoring",
138+
WrapperProperties.PLUGINS.name: plugins,
135139
"socket_timeout": 5,
136140
"connect_timeout": 5,
137141
"monitoring-connect_timeout": 3,
@@ -145,3 +149,5 @@ def test_wrapper_connection_reader_cluster_with_efm_enabled(self, test_driver: T
145149
assert 1 == result[0]
146150

147151
conn.close()
152+
153+
MonitoringThreadContainer.clean_up()

tests/integration/container/test_read_write_splitting.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
AwsWrapperError, FailoverFailedError, FailoverSuccessError,
2525
ReadWriteSplittingError, TransactionResolutionUnknownError)
2626
from aws_advanced_python_wrapper.host_list_provider import RdsHostListProvider
27+
from aws_advanced_python_wrapper.host_monitoring_plugin import \
28+
MonitoringThreadContainer
2729
from aws_advanced_python_wrapper.sql_alchemy_connection_provider import \
2830
SqlAlchemyPooledConnectionProvider
2931
from aws_advanced_python_wrapper.utils.log import Logger
@@ -61,6 +63,9 @@ def setup_method(self, request):
6163
yield
6264
self.logger.info(f"Ending test: {request.node.name}")
6365

66+
MonitoringThreadContainer.clean_up()
67+
gc.collect()
68+
6469
@pytest.fixture(scope='class')
6570
def rds_utils(self):
6671
region: str = TestEnvironment.get_current().get_info().get_region()
@@ -357,15 +362,18 @@ def test_failover_to_new_writer__switch_read_only(
357362
current_id = rds_utils.query_instance_id(conn)
358363
assert new_writer_id == current_id
359364

365+
@pytest.mark.parametrize("plugins", ["read_write_splitting,failover,host_monitoring", "read_write_splitting,failover,host_monitoring_v2"])
360366
@enable_on_features([TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED,
361367
TestEnvironmentFeatures.ABORT_CONNECTION_SUPPORTED])
362368
@enable_on_num_instances(min_instances=3)
363369
@disable_on_engines([DatabaseEngine.MYSQL])
364370
def test_failover_to_new_reader__switch_read_only(
365371
self, test_environment: TestEnvironment, test_driver: TestDriver,
366-
proxied_failover_props, conn_utils, rds_utils):
372+
proxied_failover_props, conn_utils, rds_utils, plugins):
367373
WrapperProperties.FAILOVER_MODE.set(proxied_failover_props, "reader-or-writer")
368374

375+
WrapperProperties.PLUGINS.set(proxied_failover_props, plugins)
376+
369377
target_driver_connect = DriverHelper.get_connect_func(test_driver)
370378
with AwsWrapperConnection.connect(
371379
target_driver_connect, **conn_utils.get_proxy_connect_params(), **proxied_failover_props) as conn:
@@ -404,13 +412,15 @@ def test_failover_to_new_reader__switch_read_only(
404412
current_id = rds_utils.query_instance_id(conn)
405413
assert other_reader_id == current_id
406414

415+
@pytest.mark.parametrize("plugins", ["read_write_splitting,failover,host_monitoring", "read_write_splitting,failover,host_monitoring_v2"])
407416
@enable_on_features([TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED,
408417
TestEnvironmentFeatures.ABORT_CONNECTION_SUPPORTED])
409418
@enable_on_num_instances(min_instances=3)
410419
@disable_on_engines([DatabaseEngine.MYSQL])
411420
def test_failover_reader_to_writer__switch_read_only(
412421
self, test_environment: TestEnvironment, test_driver: TestDriver,
413-
proxied_failover_props, conn_utils, rds_utils):
422+
proxied_failover_props, conn_utils, rds_utils, plugins):
423+
WrapperProperties.PLUGINS.set(proxied_failover_props, plugins)
414424
target_driver_connect = DriverHelper.get_connect_func(test_driver)
415425
with AwsWrapperConnection.connect(
416426
target_driver_connect, **conn_utils.get_proxy_connect_params(), **proxied_failover_props) as conn:
@@ -522,19 +532,21 @@ def test_pooled_connection__cluster_url_failover(
522532
new_driver_conn = conn.target_connection
523533
assert initial_driver_conn is not new_driver_conn
524534

535+
@pytest.mark.parametrize("plugins", ["read_write_splitting,failover,host_monitoring", "read_write_splitting,failover,host_monitoring_v2"])
525536
@enable_on_features([TestEnvironmentFeatures.FAILOVER_SUPPORTED, TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED,
526537
TestEnvironmentFeatures.ABORT_CONNECTION_SUPPORTED])
527538
@disable_on_engines([DatabaseEngine.MYSQL])
528539
def test_pooled_connection__failover_failed(
529540
self, test_environment: TestEnvironment, test_driver: TestDriver,
530-
rds_utils, conn_utils, proxied_failover_props):
541+
rds_utils, conn_utils, proxied_failover_props, plugins):
531542
writer_host = test_environment.get_writer().get_host()
532543
provider = SqlAlchemyPooledConnectionProvider(lambda _, __: {"pool_size": 1}, None, lambda host_info, props: writer_host in host_info.host)
533544
ConnectionProviderManager.set_connection_provider(provider)
534545

535546
WrapperProperties.FAILOVER_TIMEOUT_SEC.set(proxied_failover_props, "1")
536547
WrapperProperties.FAILURE_DETECTION_TIME_MS.set(proxied_failover_props, "1000")
537548
WrapperProperties.FAILURE_DETECTION_COUNT.set(proxied_failover_props, "1")
549+
WrapperProperties.PLUGINS.set(proxied_failover_props, plugins)
538550

539551
target_driver_connect = DriverHelper.get_connect_func(test_driver)
540552
with AwsWrapperConnection.connect(

0 commit comments

Comments
 (0)