diff --git a/common/lib/connection_plugin_chain_builder.ts b/common/lib/connection_plugin_chain_builder.ts index 8e315fde..af1417ae 100644 --- a/common/lib/connection_plugin_chain_builder.ts +++ b/common/lib/connection_plugin_chain_builder.ts @@ -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 }); } }); diff --git a/tests/unit/connection_plugin_chain_builder.test.ts b/tests/unit/connection_plugin_chain_builder.test.ts index 57615b32..373b9759 100644 --- a/tests/unit/connection_plugin_chain_builder.test.ts +++ b/tests/unit/connection_plugin_chain_builder.test.ts @@ -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)