Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed Nov 6, 2024
1 parent ff76e04 commit 0a6d2e5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion jest.integration.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"moduleFileExtensions": ["ts", "js", "json"],
"testMatch": ["<rootDir>/tests/integration/container/tests/*.(spec|test).ts|tsx"],
"testMatch": ["<rootDir>/tests/integration/container/tests/read_write_splitting.(spec|test).ts|tsx"],
"transform": {
"^.+\\.ts$": [
"ts-jest",
Expand Down
4 changes: 4 additions & 0 deletions pg/lib/pg_pool_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class AwsPgPoolClient implements AwsPoolClient {
logger.debug(err);
});
});
// this.targetPool.on("error", (err, client) => {
// console.error("Unexpected error on idle client", err);
// process.exit(-1);
// });
}

async end(): Promise<any> {
Expand Down
22 changes: 12 additions & 10 deletions tests/integration/container/tests/read_write_splitting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ describe("aurora read write splitting", () => {
// pass
}
}
if (provider !== null) {
try {
await ConnectionProviderManager.releaseResources();
ConnectionProviderManager.resetProvider();
} catch (error) {
// pass
}
}
logger.info(`Test finished: ${expect.getState().currentTestName}`);
}, 1320000);

Expand Down Expand Up @@ -481,7 +489,7 @@ describe("aurora read write splitting", () => {
"test pooled connection failover",
async () => {
const config = await initConfigWithFailover(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
const provider = new InternalPooledConnectionProvider();
provider = new InternalPooledConnectionProvider();
ConnectionProviderManager.setConnectionProvider(provider);

client = initClientFunc(config);
Expand Down Expand Up @@ -516,8 +524,6 @@ describe("aurora read write splitting", () => {
provider.logConnections();
try {
await secondaryClient.end();
await ConnectionProviderManager.releaseResources();
ConnectionProviderManager.resetProvider();
} catch (error) {
// pass
}
Expand All @@ -532,7 +538,7 @@ describe("aurora read write splitting", () => {
client = initClientFunc(config);
secondaryClient = initClientFunc(config);

const provider = new InternalPooledConnectionProvider(
provider = new InternalPooledConnectionProvider(
new AwsPoolConfig({
minConnections: 0,
maxConnections: 10,
Expand Down Expand Up @@ -658,7 +664,7 @@ describe("aurora read write splitting", () => {
const connectedReaderIds: Set<string> = new Set();
const connectionsSet: Set<any> = new Set();
try {
const provider = new InternalPooledConnectionProvider({ maxConnections: numInstances });
provider = new InternalPooledConnectionProvider({ maxConnections: numInstances });
ConnectionProviderManager.setConnectionProvider(provider);
const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
config["readerHostSelectorStrategy"] = "leastConnections";
Expand All @@ -682,8 +688,6 @@ describe("aurora read write splitting", () => {
for (const connection of connectionsSet) {
await connection.end();
}
await ConnectionProviderManager.releaseResources();
ConnectionProviderManager.resetProvider();
}
},
1000000
Expand All @@ -707,7 +711,7 @@ describe("aurora read write splitting", () => {
const numOverloadedReaderConnections = 3;
const numInstances = env.databaseInfo.instances.length;
const numTestConnections = (numInstances - 2) * numOverloadedReaderConnections;
const provider = new InternalPooledConnectionProvider({ maxConnections: numTestConnections }, myKeyFunc);
provider = new InternalPooledConnectionProvider({ maxConnections: numTestConnections }, myKeyFunc);
ConnectionProviderManager.setConnectionProvider(provider);

let overloadedReaderId;
Expand Down Expand Up @@ -745,8 +749,6 @@ describe("aurora read write splitting", () => {
for (const connection of connectionsSet) {
await connection.end();
}
await ConnectionProviderManager.releaseResources();
ConnectionProviderManager.resetProvider();
}
},
1000000
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/internal_pool_connection_provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe("internal pool connection provider test", () => {
props.set(WrapperProperties.USER.name, "mySqlUser");
props.set(WrapperProperties.PASSWORD.name, "mySqlPassword");

when(mockRdsUtils.isRdsDns(anything())).thenReturn(null);
when(mockRdsUtils.isRdsDns(anything())).thenReturn(false);
when(mockRdsUtils.isGreenInstance(anything())).thenReturn(null);
when(mockRdsUtils.isRdsInstance("instance1")).thenReturn(true);
const config = {
Expand Down Expand Up @@ -166,7 +166,7 @@ describe("internal pool connection provider test", () => {
props.set(WrapperProperties.USER.name, "mySqlUser");
props.set(WrapperProperties.PASSWORD.name, "mySqlPassword");

when(mockRdsUtils.isRdsDns(anything())).thenReturn(null);
when(mockRdsUtils.isRdsDns(anything())).thenReturn(false);
when(mockRdsUtils.isGreenInstance(anything())).thenReturn(null);
when(mockRdsUtils.isRdsInstance("instance1")).thenReturn(true);
when(mockPluginService.getDialect()).thenReturn(mockDialect);
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("internal pool connection provider test", () => {

when(mockPluginService.getCurrentHostInfo()).thenReturn(hostInfo);
when(mockPluginService.getDialect()).thenReturn(mockDialectInstance);
when(mockRdsUtils.isRdsDns(anything())).thenReturn(null);
when(mockRdsUtils.isRdsDns(anything())).thenReturn(false);
when(mockRdsUtils.isGreenInstance(anything())).thenReturn(null);
when(mockRdsUtils.isRdsInstance("instance1")).thenReturn(true);
when(mockDriverDialect.preparePoolClientProperties(anything(), anything())).thenReturn(props);
Expand Down

0 comments on commit 0a6d2e5

Please sign in to comment.