Skip to content

Commit

Permalink
chore: fix formatting and enable integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc-bq committed Dec 18, 2024
1 parent a4e0871 commit 9a825ce
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 83 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- refactor/update-read-only
paths-ignore:
- "**/*.md"
- "**/*.jpg"
Expand Down
4 changes: 2 additions & 2 deletions common/lib/plugin_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ export class PluginService implements ErrorHandler, HostListProviderService {
async abortCurrentClient(): Promise<void> {
if (this._currentClient.targetClient) {
await this._currentClient.targetClient.abort();
// this.setInTransaction(false);
// this.getSessionStateService().reset();
this.setInTransaction(false);
this.getSessionStateService().reset();
}
}

Expand Down
8 changes: 4 additions & 4 deletions common/lib/utils/sql_method_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SqlMethodUtils {
}

static doesSetAutoCommit(statements: string[], dialect: DatabaseDialect): boolean | undefined {
let autoCommit;
let autoCommit = undefined;
for (const statement of statements) {
const cleanStatement = statement
.toLowerCase()
Expand All @@ -60,7 +60,7 @@ export class SqlMethodUtils {
}

static doesSetCatalog(statements: string[], dialect: DatabaseDialect): string | undefined {
let catalog;
let catalog = undefined;
for (const statement of statements) {
const cleanStatement = statement
.toLowerCase()
Expand All @@ -73,7 +73,7 @@ export class SqlMethodUtils {
}

static doesSetSchema(statements: string[], dialect: DatabaseDialect): string | undefined {
let schema;
let schema = undefined;
for (const statement of statements) {
const cleanStatement = statement
.toLowerCase()
Expand All @@ -86,7 +86,7 @@ export class SqlMethodUtils {
}

static doesSetTransactionIsolation(statements: string[], dialect: DatabaseDialect): TransactionIsolationLevel | undefined {
let transactionIsolation;
let transactionIsolation = undefined;
for (const statement of statements) {
const cleanStatement = statement
.toLowerCase()
Expand Down
6 changes: 2 additions & 4 deletions mysql/lib/dialect/mysql_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import { DatabaseDialect, DatabaseType } from "../../../common/lib/database_dialect/database_dialect";
import { HostListProviderService } from "../../../common/lib/host_list_provider_service";
import { HostListProvider } from "../../../common/lib/host_list_provider/host_list_provider";
import {
ConnectionStringHostListProvider
} from "../../../common/lib/host_list_provider/connection_string_host_list_provider";
import { ConnectionStringHostListProvider } from "../../../common/lib/host_list_provider/connection_string_host_list_provider";
import { AwsWrapperError, UnsupportedMethodError } from "../../../common/lib/utils/errors";
import { DatabaseDialectCodes } from "../../../common/lib/database_dialect/database_dialect_codes";
import { TransactionIsolationLevel } from "../../../common/lib/utils/transaction_isolation_level";
Expand All @@ -34,7 +32,7 @@ import { Messages } from "../../../common/lib/utils/messages";
export class MySQLDatabaseDialect implements DatabaseDialect {
protected dialectName: string = this.constructor.name;
protected defaultPort: number = 3306;

getDefaultPort(): number {
return this.defaultPort;
}
Expand Down
142 changes: 71 additions & 71 deletions tests/integration/container/tests/aurora_failover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,77 +100,77 @@ describe("aurora failover", () => {
logger.info(`Test finished: ${expect.getState().currentTestName}`);
}, 1320000);

// itIf(
// "fails from writer to new writer on connection invocation",
// async () => {
// const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
// client = initClientFunc(config);
//
// await client.connect();
//
// const initialWriterId = await auroraTestUtility.queryInstanceId(client);
// expect(await auroraTestUtility.isDbInstanceWriter(initialWriterId)).toStrictEqual(true);
//
// // Crash instance 1 and nominate a new writer
// await auroraTestUtility.failoverClusterAndWaitUntilWriterChanged();
//
// await expect(async () => {
// await auroraTestUtility.queryInstanceId(client);
// }).rejects.toThrow(FailoverSuccessError);
//
// // Assert that we are connected to the new writer after failover happens
// const currentConnectionId = await auroraTestUtility.queryInstanceId(client);
// expect(await auroraTestUtility.isDbInstanceWriter(currentConnectionId)).toBe(true);
// expect(currentConnectionId).not.toBe(initialWriterId);
// },
// 1320000
// );
//
// itIf(
// "writer fails within transaction",
// async () => {
// const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
// client = initClientFunc(config);
//
// await client.connect();
// 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, "START TRANSACTION"); // start transaction
// await DriverHelper.executeQuery(env.engine, client, "INSERT INTO test3_3 VALUES (1, 'test field string 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);
//
// // Attempt to query the instance id.
// const currentConnectionId = await auroraTestUtility.queryInstanceId(client);
//
// // Assert that we are connected to the new writer after failover happens.
// expect(await auroraTestUtility.isDbInstanceWriter(currentConnectionId)).toBe(true);
//
// const nextClusterWriterId = await auroraTestUtility.getClusterWriterInstanceId();
// expect(currentConnectionId).toBe(nextClusterWriterId);
// expect(initialWriterId).not.toBe(nextClusterWriterId);
//
// // Assert that NO row has been inserted to the table.
// const result = await DriverHelper.executeQuery(env.engine, client, "SELECT count(*) from test3_3");
// if (env.engine === DatabaseEngine.PG) {
// expect((result as QueryResult).rows[0]["count"]).toBe("0");
// } else if (env.engine === DatabaseEngine.MYSQL) {
// expect(JSON.parse(JSON.stringify(result))[0][0]["count(*)"]).toBe(0);
// }
//
// await DriverHelper.executeQuery(env.engine, client, "DROP TABLE IF EXISTS test3_3");
// },
// 2000000
// );
itIf(
"fails from writer to new writer on connection invocation",
async () => {
const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
client = initClientFunc(config);

await client.connect();

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

// Crash instance 1 and nominate a new writer
await auroraTestUtility.failoverClusterAndWaitUntilWriterChanged();

await expect(async () => {
await auroraTestUtility.queryInstanceId(client);
}).rejects.toThrow(FailoverSuccessError);

// Assert that we are connected to the new writer after failover happens
const currentConnectionId = await auroraTestUtility.queryInstanceId(client);
expect(await auroraTestUtility.isDbInstanceWriter(currentConnectionId)).toBe(true);
expect(currentConnectionId).not.toBe(initialWriterId);
},
1320000
);

itIf(
"writer fails within transaction",
async () => {
const config = await initDefaultConfig(env.databaseInfo.writerInstanceEndpoint, env.databaseInfo.instanceEndpointPort, false);
client = initClientFunc(config);

await client.connect();
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, "START TRANSACTION"); // start transaction
await DriverHelper.executeQuery(env.engine, client, "INSERT INTO test3_3 VALUES (1, 'test field string 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);

// Attempt to query the instance id.
const currentConnectionId = await auroraTestUtility.queryInstanceId(client);

// Assert that we are connected to the new writer after failover happens.
expect(await auroraTestUtility.isDbInstanceWriter(currentConnectionId)).toBe(true);

const nextClusterWriterId = await auroraTestUtility.getClusterWriterInstanceId();
expect(currentConnectionId).toBe(nextClusterWriterId);
expect(initialWriterId).not.toBe(nextClusterWriterId);

// Assert that NO row has been inserted to the table.
const result = await DriverHelper.executeQuery(env.engine, client, "SELECT count(*) from test3_3");
if (env.engine === DatabaseEngine.PG) {
expect((result as QueryResult).rows[0]["count"]).toBe("0");
} else if (env.engine === DatabaseEngine.MYSQL) {
expect(JSON.parse(JSON.stringify(result))[0][0]["count(*)"]).toBe(0);
}

await DriverHelper.executeQuery(env.engine, client, "DROP TABLE IF EXISTS test3_3");
},
2000000
);

itIf(
"fails from writer and transfers session state",
Expand Down
4 changes: 2 additions & 2 deletions tests/plugin_manager_benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ suite(
}),

add("initHostProviderWith10Plugins", async () => {
const pluginManagerWithPlugins = await initPluginManagerWithPlugins(10, instance(mockPluginService), propsWithPlugins);;
const pluginManagerWithPlugins = await initPluginManagerWithPlugins(10, instance(mockPluginService), propsWithPlugins);
return async () =>
await pluginManagerWithPlugins.initHostProvider(
new HostInfoBuilder({ hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy() }).withHost("host").build(),
Expand Down Expand Up @@ -325,7 +325,7 @@ suite(
}),

add("notifyConnectionChangedWith10Plugins", async () => {
const pluginManagerWithPlugins = await initPluginManagerWithPlugins(10, instance(mockPluginService), propsWithPlugins);;
const pluginManagerWithPlugins = await initPluginManagerWithPlugins(10, instance(mockPluginService), propsWithPlugins);
return async () =>
await pluginManagerWithPlugins.notifyConnectionChanged(new Set<HostChangeOptions>([HostChangeOptions.INITIAL_CONNECTION]), null);
}),
Expand Down

0 comments on commit 9a825ce

Please sign in to comment.