Skip to content

Commit

Permalink
test enable
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed Oct 18, 2024
1 parent dac9286 commit a915126
Showing 1 changed file with 62 additions and 56 deletions.
118 changes: 62 additions & 56 deletions tests/integration/container/tests/read_write_splitting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,72 +463,72 @@ describe("aurora read write splitting", () => {
);

itIfMinThreeInstance(
"test set read only reuse cached connection",
"test pooled connection failover",
async () => {
const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
const config = await initConfigWithFailover(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
client = initClientFunc(config);
secondaryClient = initClientFunc(config);

const provider = new InternalPooledConnectionProvider(
new AwsPoolConfig({ idleTimeoutMillis: 7000, maxConnections: 10, maxIdleConnections: 10 })
);

ConnectionProviderManager.setConnectionProvider(provider);

client.on("error", (error: any) => {
logger.debug(`event emitter threw error: ${error.message}`);
logger.debug(error.stack);
});

secondaryClient.on("error", (error: any) => {
logger.debug(`event emitter threw error: ${error.message}`);
logger.debug(error.stack);
});
await client.connect();
await client.end();
const initialWriterId = await auroraTestUtility.queryInstanceId(client);
provider.logConnections();

await secondaryClient.connect();
expect(client).not.toBe(secondaryClient);
await auroraTestUtility.failoverClusterAndWaitUntilWriterChanged();
logger.debug("FINISHED FAILVER");
await expect(async () => {
await auroraTestUtility.queryInstanceId(client);
}).rejects.toThrow(FailoverSuccessError);
logger.debug("FINISHED QUERY AFER FAILOVER");

const newWriterId = await auroraTestUtility.queryInstanceId(client);

expect(newWriterId).not.toBe(initialWriterId);
provider.logConnections();

await secondaryClient.end();
await provider.releaseResources();
ConnectionProviderManager.resetProvider();
},
1000000
);

itIfMinThreeInstance(
"test pooled connection failover",
"test set read only reuse cached connection",
async () => {
const config = await initConfigWithFailover(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
client = initClientFunc(config);
secondaryClient = initClientFunc(config);

const provider = new InternalPooledConnectionProvider(
new AwsPoolConfig({ idleTimeoutMillis: 7000, maxConnections: 10, maxIdleConnections: 10 })
);

ConnectionProviderManager.setConnectionProvider(provider);

client.on("error", (error: any) => {
logger.debug(`event emitter threw error: ${error.message}`);
logger.debug(error.stack);
});

secondaryClient.on("error", (error: any) => {
logger.debug(`event emitter threw error: ${error.message}`);
logger.debug(error.stack);
});
await client.connect();
const initialWriterId = await auroraTestUtility.queryInstanceId(client);
provider.logConnections();

await auroraTestUtility.failoverClusterAndWaitUntilWriterChanged();
console.log("FINISHED FAILVER");
await expect(async () => {
await auroraTestUtility.queryInstanceId(client);
}).rejects.toThrow(FailoverSuccessError);
console.log("FINISHED QUERY AFER FAILOVER");

const newWriterId = await auroraTestUtility.queryInstanceId(client);
await client.end();

expect(newWriterId).not.toBe(initialWriterId);
provider.logConnections();
await secondaryClient.connect();
expect(client).not.toBe(secondaryClient);

await secondaryClient.end();
await provider.releaseResources();
ConnectionProviderManager.resetProvider();
},
Expand Down Expand Up @@ -574,43 +574,49 @@ describe("aurora read write splitting", () => {
1000000
);

it.only("test pooled connection failover in transaction", async () => {
const config = await initConfigWithFailover(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
client = initClientFunc(config);
itIfMinThreeInstance(
"test pooled connection failover in transaction",
async () => {
const config = await initConfigWithFailover(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
client = initClientFunc(config);

const provider = new InternalPooledConnectionProvider(new AwsPoolConfig({ idleTimeoutMillis: 7000, maxConnections: 10, maxIdleConnections: 10 }));
await provider.releaseResources(); // make sure there's no pool's left after prior test
const provider = new InternalPooledConnectionProvider(
new AwsPoolConfig({ idleTimeoutMillis: 7000, maxConnections: 10, maxIdleConnections: 10 })
);
await provider.releaseResources(); // make sure there's no pool's left after prior test

ConnectionProviderManager.setConnectionProvider(provider);
ConnectionProviderManager.setConnectionProvider(provider);

client.on("error", (error: any) => {
logger.debug(`event emitter threw error: ${error.message}`);
logger.debug(error.stack);
});
client.on("error", (error: any) => {
logger.debug(`event emitter threw error: ${error.message}`);
logger.debug(error.stack);
});

await client.connect();
await client.connect();

const initialWriterId = await auroraTestUtility.queryInstanceId(client);
expect(await auroraTestUtility.isDbInstanceWriter(initialWriterId)).toStrictEqual(true);
const initialWriterId = await auroraTestUtility.queryInstanceId(client);
expect(await auroraTestUtility.isDbInstanceWriter(initialWriterId)).toStrictEqual(true);

await DriverHelper.executeQuery(env.engine, client, "DROP TABLE IF EXISTS test3_3");
await DriverHelper.executeQuery(env.engine, client, "CREATE TABLE test3_3 (id int not null primary key, test3_3_field varchar(255) not null)");
await DriverHelper.executeQuery(env.engine, client, "DROP TABLE IF EXISTS test3_3");
await DriverHelper.executeQuery(env.engine, client, "CREATE TABLE test3_3 (id int not null primary key, test3_3_field varchar(255) not null)");

await DriverHelper.executeQuery(env.engine, client, "START TRANSACTION READ ONLY"); // start transaction
await DriverHelper.executeQuery(env.engine, client, "SELECT 1");
// Crash instance 1 and nominate a new writer
await auroraTestUtility.failoverClusterAndWaitUntilWriterChanged();
await DriverHelper.executeQuery(env.engine, client, "START TRANSACTION READ ONLY"); // start transaction
await DriverHelper.executeQuery(env.engine, client, "SELECT 1");
// Crash instance 1 and nominate a new writer
await auroraTestUtility.failoverClusterAndWaitUntilWriterChanged();

await expect(async () => {
await DriverHelper.executeQuery(env.engine, client, "INSERT INTO test3_3 VALUES (2, 'test field string 2')");
}).rejects.toThrow(TransactionResolutionUnknownError);
await expect(async () => {
await DriverHelper.executeQuery(env.engine, client, "INSERT INTO test3_3 VALUES (2, 'test field string 2')");
}).rejects.toThrow(TransactionResolutionUnknownError);

// Attempt to query the instance id.
const nextWriterId = await auroraTestUtility.queryInstanceId(client);
expect(nextWriterId).not.toBe(initialWriterId);
await DriverHelper.executeQuery(env.engine, client, "COMMIT");
// Attempt to query the instance id.
const nextWriterId = await auroraTestUtility.queryInstanceId(client);
expect(nextWriterId).not.toBe(initialWriterId);
await DriverHelper.executeQuery(env.engine, client, "COMMIT");

await provider.releaseResources();
ConnectionProviderManager.resetProvider();
}, 1000000);
await provider.releaseResources();
ConnectionProviderManager.resetProvider();
},
1000000
);
});

0 comments on commit a915126

Please sign in to comment.