Skip to content

Commit 3391cf4

Browse files
authored
fix: avoid modifying static variable directly in the code (#257)
1 parent 236e98b commit 3391cf4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

common/lib/connection_plugin_chain_builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ export class ConnectionPluginChainBuilder {
9292
const factoryInfo = ConnectionPluginChainBuilder.PLUGIN_FACTORIES.get(p);
9393
if (factoryInfo) {
9494
if (factoryInfo.weight === ConnectionPluginChainBuilder.WEIGHT_RELATIVE_TO_PRIOR_PLUGIN) {
95-
factoryInfo.weight = ++lastWeight;
95+
lastWeight++;
9696
} else {
9797
lastWeight = factoryInfo.weight;
9898
}
99-
pluginFactoryInfoList.push(factoryInfo);
99+
pluginFactoryInfoList.push({ factory: factoryInfo.factory, weight: lastWeight });
100100
}
101101
});
102102

tests/unit/connection_plugin_chain_builder.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,24 @@ describe("testConnectionPluginChainBuilder", () => {
7676

7777
it("sort plugins with stick to prior", async () => {
7878
const props = new Map();
79+
80+
props.set(WrapperProperties.PLUGINS.name, "executeTime,connectTime,iam");
81+
82+
let result = await ConnectionPluginChainBuilder.getPlugins(
83+
mockPluginServiceInstance,
84+
props,
85+
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider)
86+
);
87+
88+
expect(result.length).toBe(4);
89+
expect(result[0]).toBeInstanceOf(ExecuteTimePlugin);
90+
expect(result[1]).toBeInstanceOf(ConnectTimePlugin);
91+
expect(result[2]).toBeInstanceOf(IamAuthenticationPlugin);
92+
93+
// Test again to make sure the previous sort does not impact future plugin chains
7994
props.set(WrapperProperties.PLUGINS.name, "iam,executeTime,connectTime,failover");
8095

81-
const result = await ConnectionPluginChainBuilder.getPlugins(
96+
result = await ConnectionPluginChainBuilder.getPlugins(
8297
mockPluginServiceInstance,
8398
props,
8499
new ConnectionProviderManager(mockDefaultConnProvider, mockEffectiveConnProvider)

0 commit comments

Comments
 (0)