Skip to content

Commit d89ff9c

Browse files
authored
test: configure fake timers for iam tests (#353)
1 parent 1bbb070 commit d89ff9c

7 files changed

+26
-15
lines changed

Diff for: docs/using-the-nodejs-wrapper/using-plugins/UsingTheReadWriteSplittingPlugin.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ props.set("connectionProvider", provider);
103103

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

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

108108
> [!IMPORTANT]
109+
> To ensure the provider can close the pools, call `await PluginManager.releaseResources()` first.
110+
>
109111
> 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.
110112
111113
### Reader Selection

Diff for: examples/aws_driver_example/aws_interal_connection_pool_password_warning_postgres_example.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ try {
7272
} finally {
7373
await newClient.end();
7474
}
75+
7576
// Closes all pools and removes all cached pool connections.
7677
await provider.releaseResources();
7778

@@ -90,8 +91,8 @@ try {
9091
await newClient2.connect();
9192
// Will not reach - exception will be thrown
9293
} finally {
94+
// Clean up resources used by the plugins.
95+
await PluginManager.releaseResources();
96+
9397
logger.debug("example complete");
9498
}
95-
96-
// Clean up resources used by the plugins.
97-
await PluginManager.releaseResources();

Diff for: examples/aws_driver_example/aws_internal_connection_pool_password_warning_mysql_example.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ try {
7272
} finally {
7373
await newClient.end();
7474
}
75+
7576
// Closes all pools and removes all cached pool connections.
7677
await provider.releaseResources();
7778

@@ -90,8 +91,8 @@ try {
9091
await newClient2.connect();
9192
// Will not reach - exception will be thrown.
9293
} finally {
94+
// Clean up resources used by the plugins.
95+
await PluginManager.releaseResources();
96+
9397
logger.debug("example complete");
9498
}
95-
96-
// Clean up resources used by the plugins.
97-
await PluginManager.releaseResources();

Diff for: examples/aws_driver_example/aws_internal_connection_pooling_mysql_example.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ try {
108108
} finally {
109109
await client.end();
110110

111+
// Clean up resources used by the plugins.
112+
await PluginManager.releaseResources();
113+
111114
// If configured to use internal connection pools, close them here.
112115
await provider.releaseResources();
113116
}
@@ -138,6 +141,3 @@ async function queryWithFailoverHandling(client: AwsMySQLClient, query: string)
138141
}
139142
}
140143
}
141-
142-
// Clean up resources used by the plugins.
143-
await PluginManager.releaseResources();

Diff for: examples/aws_driver_example/aws_internal_connection_pooling_postgres_example.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ try {
108108
} finally {
109109
await client.end();
110110

111+
// Clean up resources used by the plugins.
112+
await PluginManager.releaseResources();
113+
111114
// If configured to use internal connection pools, close them here.
112115
await provider.releaseResources();
113116
}
@@ -138,6 +141,3 @@ async function queryWithFailoverHandling(client: AwsPGClient, query: string) {
138141
}
139142
}
140143
}
141-
142-
// Clean up resources used by the plugins.
143-
await PluginManager.releaseResources();

Diff for: tests/integration/container/tests/iam_authentication.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ async function validateConnection(client: AwsPGClient | AwsMySQLClient) {
8484
describe("iam authentication", () => {
8585
beforeEach(async () => {
8686
logger.info(`Test started: ${expect.getState().currentTestName}`);
87-
jest.useFakeTimers();
87+
jest.useFakeTimers({
88+
doNotFake: ["nextTick"]
89+
});
8890
env = await TestEnvironment.getCurrent();
8991
driver = DriverHelper.getDriverForDatabaseEngine(env.engine);
9092
initClientFunc = DriverHelper.getClient(driver);
@@ -97,6 +99,11 @@ describe("iam authentication", () => {
9799
logger.info(`Test finished: ${expect.getState().currentTestName}`);
98100
}, 1320000);
99101

102+
afterAll(async () => {
103+
jest.runOnlyPendingTimers();
104+
jest.useRealTimers();
105+
});
106+
100107
itIf(
101108
"iam wrong database username",
102109
async () => {

Diff for: tests/integration/container/tests/read_write_splitting.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ describe("aurora read write splitting", () => {
115115
// pass
116116
}
117117
}
118+
await PluginManager.releaseResources();
118119
if (provider !== null) {
119120
try {
120121
await provider.releaseResources();
121122
} catch (error) {
122123
// pass
123124
}
124125
}
125-
await PluginManager.releaseResources();
126126
logger.info(`Test finished: ${expect.getState().currentTestName}`);
127127
}, 1320000);
128128

0 commit comments

Comments
 (0)