Skip to content

Commit

Permalink
test: refactor HikariCP integration tests to be more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
crystall-bitquill committed Jan 29, 2024
1 parent f52cc42 commit 73c86a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: 'junit-report'
name: 'junit-report-integration'
path: build/reports/tests/
retention-days: 5

Expand All @@ -82,6 +82,6 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: 'junit-report'
name: 'junit-report-community'
path: build/reports/tests/
retention-days: 5
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
package testsuite.integration.container;

import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.DBCluster;
import software.amazon.awssdk.services.rds.model.DBClusterMember;
Expand Down Expand Up @@ -135,6 +134,7 @@ public abstract class AuroraMysqlIntegrationBaseTest {

protected String[] instanceIDs; // index 0 is always writer!
protected int clusterSize = 0;
protected List<String> clusterTopology;

protected final ContainerHelper containerHelper = new ContainerHelper();
protected final AuroraTestUtility auroraUtil = new AuroraTestUtility(DB_REGION);
Expand Down Expand Up @@ -200,6 +200,7 @@ public void setUpEach() throws InterruptedException, SQLException {
assertTrue(clusterSize >= 2); // many tests assume that cluster contains at least a writer and a reader
assertTrue(isDBInstanceWriter(instanceIDs[0]));
makeSureInstancesUp(instanceIDs);
clusterTopology = getTopologyEndpoints();
}

protected Properties initDefaultPropsNoTimeouts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLTransientConnectionException;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -64,22 +63,6 @@ public class HikariCPIntegrationTest extends AuroraMysqlIntegrationBaseTest {
private static Log log = null;
private static final String URL_SUFFIX = PROXIED_DOMAIN_NAME_SUFFIX + ":" + MYSQL_PROXY_PORT;
private static HikariDataSource data_source = null;
private final List<String> clusterTopology = fetchTopology();

private List<String> fetchTopology() {
try {
List<String> topology = getTopologyEndpoints();
// topology should contain a writer and at least one reader
if (topology == null || topology.size() < 2) {
fail("Topology does not contain the required instances");
}
return topology;
} catch (SQLException e) {
fail("Couldn't fetch cluster topology");
}

return null;
}

@BeforeAll
static void setup() throws ClassNotFoundException {
Expand All @@ -95,7 +78,12 @@ public void teardown() {
}

@BeforeEach
public void setUpTest() throws SQLException {
public void setUpTest() {
// topology should contain a writer and at least one reader
if (clusterTopology == null || clusterTopology.size() < 2) {
fail("Topology does not contain the required instances");
}

String writerEndpoint = clusterTopology.get(0);

String jdbcUrl = DB_CONN_STR_PREFIX + writerEndpoint + URL_SUFFIX;
Expand Down

0 comments on commit 73c86a0

Please sign in to comment.