Skip to content

Commit

Permalink
test: configure fake timers for iam tests (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophia-bq authored Dec 13, 2024
1 parent 1bbb070 commit d89ff9c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ props.set("connectionProvider", provider);

4. Continue as normal: create connections and use them as needed.

5. When you are finished using all connections, call `await provider.releaseResources()`.
5. When you are finished using all connections, call `await PluginManager.releaseResources()`, and then `await provider.releaseResources()`.

> [!IMPORTANT]
> To ensure the provider can close the pools, call `await PluginManager.releaseResources()` first.
>
> You must call `await provider.releaseResources()` to close the internal connection pools when you are finished using all connections. Unless `await ConnectionProviderManager.releaseResources()` is called, the wrapper driver will keep the pools open so that they can be shared between connections.
### Reader Selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ try {
} finally {
await newClient.end();
}

// Closes all pools and removes all cached pool connections.
await provider.releaseResources();

Expand All @@ -90,8 +91,8 @@ try {
await newClient2.connect();
// Will not reach - exception will be thrown
} finally {
// Clean up resources used by the plugins.
await PluginManager.releaseResources();

logger.debug("example complete");
}

// Clean up resources used by the plugins.
await PluginManager.releaseResources();
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ try {
} finally {
await newClient.end();
}

// Closes all pools and removes all cached pool connections.
await provider.releaseResources();

Expand All @@ -90,8 +91,8 @@ try {
await newClient2.connect();
// Will not reach - exception will be thrown.
} finally {
// Clean up resources used by the plugins.
await PluginManager.releaseResources();

logger.debug("example complete");
}

// Clean up resources used by the plugins.
await PluginManager.releaseResources();
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ try {
} finally {
await client.end();

// Clean up resources used by the plugins.
await PluginManager.releaseResources();

// If configured to use internal connection pools, close them here.
await provider.releaseResources();
}
Expand Down Expand Up @@ -138,6 +141,3 @@ async function queryWithFailoverHandling(client: AwsMySQLClient, query: string)
}
}
}

// Clean up resources used by the plugins.
await PluginManager.releaseResources();
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ try {
} finally {
await client.end();

// Clean up resources used by the plugins.
await PluginManager.releaseResources();

// If configured to use internal connection pools, close them here.
await provider.releaseResources();
}
Expand Down Expand Up @@ -138,6 +141,3 @@ async function queryWithFailoverHandling(client: AwsPGClient, query: string) {
}
}
}

// Clean up resources used by the plugins.
await PluginManager.releaseResources();
9 changes: 8 additions & 1 deletion tests/integration/container/tests/iam_authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ async function validateConnection(client: AwsPGClient | AwsMySQLClient) {
describe("iam authentication", () => {
beforeEach(async () => {
logger.info(`Test started: ${expect.getState().currentTestName}`);
jest.useFakeTimers();
jest.useFakeTimers({
doNotFake: ["nextTick"]
});
env = await TestEnvironment.getCurrent();
driver = DriverHelper.getDriverForDatabaseEngine(env.engine);
initClientFunc = DriverHelper.getClient(driver);
Expand All @@ -97,6 +99,11 @@ describe("iam authentication", () => {
logger.info(`Test finished: ${expect.getState().currentTestName}`);
}, 1320000);

afterAll(async () => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

itIf(
"iam wrong database username",
async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ describe("aurora read write splitting", () => {
// pass
}
}
await PluginManager.releaseResources();
if (provider !== null) {
try {
await provider.releaseResources();
} catch (error) {
// pass
}
}
await PluginManager.releaseResources();
logger.info(`Test finished: ${expect.getState().currentTestName}`);
}, 1320000);

Expand Down

0 comments on commit d89ff9c

Please sign in to comment.