Skip to content

Commit a1d27eb

Browse files
committedMar 28, 2024·
fix: failing integration tests due to not waiting for TAZ cluster to fully failover
1 parent a29a5f0 commit a1d27eb

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed
 

Diff for: ‎tests/integration/container/utils/rds_test_utility.py

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def failover_cluster_and_wait_until_writer_changed(
156156
sleep(1)
157157
cluster_address = socket.gethostbyname(cluster_endpoint)
158158

159+
self.make_sure_instances_up(self.get_instance_ids())
159160
self.logger.debug("Testing.FinishedFailover", initial_writer_id, str((perf_counter_ns() - start) / 1_000_000))
160161

161162
def failover_cluster(self, cluster_id: Optional[str] = None) -> None:

Diff for: ‎tests/integration/host/src/test/java/integration/host/TestEnvironment.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package integration.host;
1818

19-
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
2119
import com.fasterxml.jackson.core.JsonProcessingException;
2220
import com.fasterxml.jackson.databind.ObjectMapper;
2321
import eu.rekawek.toxiproxy.ToxiproxyClient;
@@ -44,6 +42,7 @@
4442
import java.util.concurrent.ExecutorService;
4543
import java.util.concurrent.Executors;
4644
import java.util.concurrent.TimeUnit;
45+
import java.util.concurrent.atomic.AtomicInteger;
4746
import java.util.logging.Logger;
4847
import org.testcontainers.containers.GenericContainer;
4948
import org.testcontainers.containers.Network;
@@ -70,6 +69,7 @@ public class TestEnvironment implements AutoCloseable {
7069
private static final TestEnvironmentConfiguration config = new TestEnvironmentConfiguration();
7170
private static final boolean USE_OTLP_CONTAINER_FOR_TRACES = false;
7271

72+
private static final AtomicInteger ipAddressUsageRefCount = new AtomicInteger(0);
7373
private final TestEnvironmentInfo info =
7474
new TestEnvironmentInfo(); // only this info is passed to test container
7575

@@ -102,12 +102,22 @@ private TestEnvironment(TestEnvironmentRequest request) {
102102
}
103103

104104
public static TestEnvironment build(TestEnvironmentRequest request) throws IOException {
105+
DatabaseEngineDeployment deployment = request.getDatabaseEngineDeployment();
106+
if (deployment == DatabaseEngineDeployment.AURORA
107+
|| deployment == DatabaseEngineDeployment.RDS
108+
|| deployment == DatabaseEngineDeployment.RDS_MULTI_AZ) {
109+
// These environment require creating external database cluster that should be publicly available.
110+
// Corresponding AWS Security Groups should be configured and the test task runner IP address
111+
// should be whitelisted.
112+
ipAddressUsageRefCount.incrementAndGet();
113+
}
114+
105115
LOGGER.finest("Building test env: " + request.getEnvPreCreateIndex());
106116
preCreateEnvironment(request.getEnvPreCreateIndex());
107117

108118
TestEnvironment env;
109119

110-
switch (request.getDatabaseEngineDeployment()) {
120+
switch (deployment) {
111121
case DOCKER:
112122
env = new TestEnvironment(request);
113123
initDatabaseParams(env);
@@ -185,8 +195,7 @@ private static TestEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentR
185195
if (result instanceof Exception) {
186196
throw new RuntimeException((Exception) result);
187197
}
188-
if (result instanceof TestEnvironment) {
189-
TestEnvironment resultTestEnvironment = (TestEnvironment) result;
198+
if (result instanceof TestEnvironment resultTestEnvironment) {
190199
LOGGER.finer(() -> String.format("Use pre-created DB cluster: %s.cluster-%s",
191200
resultTestEnvironment.auroraClusterName, resultTestEnvironment.auroraClusterDomain));
192201

@@ -894,7 +903,11 @@ public void close() throws Exception {
894903

895904
private void deleteDbCluster() {
896905
if (!this.reuseAuroraDbCluster && !StringUtils.isNullOrEmpty(this.runnerIP)) {
897-
auroraUtil.ec2DeauthorizesIP(runnerIP);
906+
if (ipAddressUsageRefCount.decrementAndGet() == 0) {
907+
// Another test environments are still in use of test task runner IP address.
908+
// The last execute tst environment will do the cleanup.
909+
auroraUtil.ec2DeauthorizesIP(runnerIP);
910+
}
898911
}
899912

900913
if (!this.reuseAuroraDbCluster) {

0 commit comments

Comments
 (0)
Please sign in to comment.