Skip to content

Commit

Permalink
fix: avoid modifying static variable directly in the code (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc-bq authored Oct 23, 2024
1 parent 236e98b commit 3391cf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions common/lib/connection_plugin_chain_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class ConnectionPluginChainBuilder {
const factoryInfo = ConnectionPluginChainBuilder.PLUGIN_FACTORIES.get(p);
if (factoryInfo) {
if (factoryInfo.weight === ConnectionPluginChainBuilder.WEIGHT_RELATIVE_TO_PRIOR_PLUGIN) {
factoryInfo.weight = ++lastWeight;
lastWeight++;
} else {
lastWeight = factoryInfo.weight;
}
pluginFactoryInfoList.push(factoryInfo);
pluginFactoryInfoList.push({ factory: factoryInfo.factory, weight: lastWeight });
}
});

Expand Down
17 changes: 16 additions & 1 deletion tests/unit/connection_plugin_chain_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,24 @@ describe("testConnectionPluginChainBuilder", () => {

it("sort plugins with stick to prior", async () => {
const props = new Map();

props.set(WrapperProperties.PLUGINS.name, "executeTime,connectTime,iam");

let result = await ConnectionPluginChainBuilder.getPlugins(
mockPluginServiceInstance,
props,
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider)
);

expect(result.length).toBe(4);
expect(result[0]).toBeInstanceOf(ExecuteTimePlugin);
expect(result[1]).toBeInstanceOf(ConnectTimePlugin);
expect(result[2]).toBeInstanceOf(IamAuthenticationPlugin);

// Test again to make sure the previous sort does not impact future plugin chains
props.set(WrapperProperties.PLUGINS.name, "iam,executeTime,connectTime,failover");

const result = await ConnectionPluginChainBuilder.getPlugins(
result = await ConnectionPluginChainBuilder.getPlugins(
mockPluginServiceInstance,
props,
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider)
Expand Down

0 comments on commit 3391cf4

Please sign in to comment.