Skip to content

Commit

Permalink
fix: integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc-bq committed Dec 24, 2024
1 parent 023ba38 commit 7e72d86
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
1 change: 0 additions & 1 deletion common/lib/client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface ClientWrapper {
readonly hostInfo: HostInfo;
readonly properties: Map<string, any>;
readonly id: string;
readonly sessionState: SessionState;

query(sql: any): Promise<any>;

Expand Down
1 change: 0 additions & 1 deletion common/lib/mysql_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class MySQLClientWrapper implements ClientWrapper {
readonly hostInfo: HostInfo;
readonly properties: Map<string, string>;
readonly id: string;
readonly sessionState: SessionState = new SessionState();

/**
* Creates a wrapper for the target community driver client.
Expand Down
12 changes: 4 additions & 8 deletions mysql/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ export class AwsMySQLClient extends AwsClient {
async setReadOnly(readOnly: boolean): Promise<Query | void> {
this.pluginService.getSessionStateService().setupPristineReadOnly();
const result = await this.queryWithoutUpdate({ sql: `SET SESSION TRANSACTION READ ${readOnly ? "ONLY" : "WRITE"}` });
this.targetClient.sessionState.readOnly.value = readOnly;
this.pluginService.getSessionStateService().updateReadOnly(readOnly);
return result;
}

isReadOnly(): boolean {
return this.targetClient.sessionState.readOnly.value;
return this.pluginService.getSessionStateService().getReadOnly();
}

async setAutoCommit(autoCommit: boolean): Promise<Query | void> {
Expand All @@ -113,24 +112,22 @@ export class AwsMySQLClient extends AwsClient {
setting = "0";
}
const result = await this.queryWithoutUpdate({ sql: `SET AUTOCOMMIT=${setting}` });
this.targetClient.sessionState.autoCommit.value = autoCommit;
this.pluginService.getSessionStateService().setAutoCommit(autoCommit);
return result;
}

getAutoCommit(): boolean {
return this.targetClient.sessionState.autoCommit.value;
return this.pluginService.getSessionStateService().getAutoCommit();
}

async setCatalog(catalog: string): Promise<Query | void> {
this.pluginService.getSessionStateService().setupPristineCatalog();
await this.queryWithoutUpdate({ sql: `USE ${catalog}` });
this.targetClient.sessionState.catalog.value = catalog;
this.pluginService.getSessionStateService().setCatalog(catalog);
}

getCatalog(): string {
return this.targetClient.sessionState.catalog.value;
return this.pluginService.getSessionStateService().getCatalog();
}

async setSchema(schema: string): Promise<Query | void> {
Expand Down Expand Up @@ -161,12 +158,11 @@ export class AwsMySQLClient extends AwsClient {
throw new AwsWrapperError(Messages.get("Client.invalidTransactionIsolationLevel", String(level)));
}

this.targetClient.sessionState.transactionIsolation.value = level;
this.pluginService.getSessionStateService().setTransactionIsolation(level);
}

getTransactionIsolation(): number {
return this.targetClient.sessionState.transactionIsolation.value;
return this.pluginService.getSessionStateService().getTransactionIsolation();
}

async end() {
Expand Down
2 changes: 0 additions & 2 deletions pg/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class AwsPGClient extends AwsClient {
async setReadOnly(readOnly: boolean): Promise<QueryResult | void> {
this.pluginService.getSessionStateService().setupPristineReadOnly();
const result = await this.queryWithoutUpdate(`SET SESSION CHARACTERISTICS AS TRANSACTION READ ${readOnly ? "ONLY" : "WRITE"}`);
this.targetClient.sessionState.readOnly.value = readOnly;
this.pluginService.getSessionStateService().updateReadOnly(readOnly);
return result;
}
Expand Down Expand Up @@ -149,7 +148,6 @@ export class AwsPGClient extends AwsClient {

this.pluginService.getSessionStateService().setupPristineSchema();
const result = await this.queryWithoutUpdate(`SET search_path TO ${schema};`);
this.targetClient.sessionState.schema.value = schema;
this.pluginService.getSessionStateService().setSchema(schema);
return result;
}
Expand Down
17 changes: 7 additions & 10 deletions tests/integration/container/tests/session_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,20 @@ describe("session state", () => {

await client.getPluginService().setCurrentClient(newClient.targetClient);

expect(client.targetClient.sessionState.readOnly.value).toBe(true);
expect(client.targetClient.sessionState.autoCommit.value).toBe(false);
expect(client.targetClient.sessionState.catalog.value).toBe(env.databaseInfo.defaultDbName);
expect(client.targetClient.sessionState.schema.value).toBe(undefined);
expect(client.targetClient.sessionState.transactionIsolation.value).toBe(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE);
expect(client.getAutoCommit()).toBe(true);
expect(client.getCatalog()).toBe(env.databaseInfo.defaultDbName);
expect(client.getSchema()).toBe(undefined);
expect(client.getTransactionIsolation()).toBe(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE);
} else if (driver === TestDriver.PG) {
await newClient.setReadOnly(true);
await newClient.setSchema(env.databaseInfo.defaultDbName);
await newClient.setTransactionIsolation(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE);

await client.getPluginService().setCurrentClient(newClient.targetClient);

expect(client.targetClient.sessionState.readOnly.value).toBe(true);
expect(client.targetClient.sessionState.autoCommit.value).toBe(undefined);
expect(client.targetClient.sessionState.catalog.value).toBe(undefined);
expect(client.targetClient.sessionState.schema.value).toBe(env.databaseInfo.defaultDbName);
expect(client.targetClient.sessionState.transactionIsolation.value).toBe(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE);
expect(client.getReadOnly()).toBe(true);
expect(client.getSchema()).toBe(env.databaseInfo.defaultDbName);
expect(client.getTransactionIsolation()).toBe(TransactionIsolationLevel.TRANSACTION_SERIALIZABLE);
}
} catch (e) {
await client.end();
Expand Down

0 comments on commit 7e72d86

Please sign in to comment.