Path: redb-route/tests/redb.Route.Tests.RabbitMQ/RabbitMQConnectionPoolTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.RabbitMQ/RabbitMQConnectionPoolTests.cs ---- using redb.Route.Core; using redb.Route.RabbitMQ; namespace redb.Route.Tests.RabbitMQ; /// /// Pure-logic tests for the connection-pool key resolution implemented in /// . These do not require a running broker — they verify /// that the pool's identity model behaves as designed: /// /// factory:{name} when connectionFactory=name is set on the URI. /// inline:{host}:{port}/{vhost}@{user}[#ssl] otherwise. /// Two factories with identical inline parameters but different names produce /// two distinct keys (deliberate: factory name is the connection identity). /// /// public sealed class RabbitMQConnectionPoolTests { private static RabbitMQEndpointOptions OptionsFromUri(string uri) { var parsed = EndpointUriParser.Parse(uri); var opts = new RabbitMQEndpointOptions(); opts.BindFromUri(parsed.RawParameters); opts.Validate(); return opts; } [Fact] public void ResolveKey_FactoryName_ProducesFactoryKey() { var opts = OptionsFromUri("rabbitmq://q?connectionFactory=primary"); RabbitMQComponent.ResolveConnectionKey(opts).Should().Be("factory:primary"); } [Fact] public void ResolveKey_NoFactory_ProducesInlineKey() { var opts = OptionsFromUri("rabbitmq://q?host=broker.example.com&port=5672&virtualHost=/&username=alice"); RabbitMQComponent.ResolveConnectionKey(opts) .Should().Be("inline:broker.example.com:5672//@alice"); } [Fact] public void ResolveKey_InlineWithSsl_AppendsSslMarker() { var opts = OptionsFromUri("rabbitmq://q?host=secure.example.com&port=5671&username=bob&ssl=true"); RabbitMQComponent.ResolveConnectionKey(opts) .Should().Be("inline:secure.example.com:5671//@bob#ssl"); } [Fact] public void ResolveKey_TwoEndpointsSameFactoryName_ShareKey() { var a = OptionsFromUri("rabbitmq://qA?connectionFactory=primary"); var b = OptionsFromUri("rabbitmq://qB?connectionFactory=primary"); RabbitMQComponent.ResolveConnectionKey(a) .Should().Be(RabbitMQComponent.ResolveConnectionKey(b)); } [Fact] public void ResolveKey_TwoFactoriesDifferentNamesSameInlineParams_ProduceDistinctKeys() { // Per design: factory name IS the connection identity. Two named factories with // identical broker parameters MUST yield two distinct connections — this lets a // single application open N parallel connections to the same broker on purpose. var a = OptionsFromUri("rabbitmq://q?connectionFactory=conn1"); var b = OptionsFromUri("rabbitmq://q?connectionFactory=conn2"); var keyA = RabbitMQComponent.ResolveConnectionKey(a); var keyB = RabbitMQComponent.ResolveConnectionKey(b); keyA.Should().Be("factory:conn1"); keyB.Should().Be("factory:conn2"); keyA.Should().NotBe(keyB); } [Fact] public void ResolveKey_TwoEndpointsIdenticalInlineParams_ShareKey() { var a = OptionsFromUri("rabbitmq://qA?host=h&port=5672&virtualHost=/&username=u"); var b = OptionsFromUri("rabbitmq://qB?host=h&port=5672&virtualHost=/&username=u"); RabbitMQComponent.ResolveConnectionKey(a) .Should().Be(RabbitMQComponent.ResolveConnectionKey(b)); } [Fact] public void ResolveKey_DifferentInlineHosts_ProduceDistinctKeys() { var a = OptionsFromUri("rabbitmq://q?host=h1&username=u"); var b = OptionsFromUri("rabbitmq://q?host=h2&username=u"); RabbitMQComponent.ResolveConnectionKey(a) .Should().NotBe(RabbitMQComponent.ResolveConnectionKey(b)); } [Fact] public void ResolveKey_DifferentInlineUsers_ProduceDistinctKeys() { var a = OptionsFromUri("rabbitmq://q?host=h&username=alice"); var b = OptionsFromUri("rabbitmq://q?host=h&username=bob"); RabbitMQComponent.ResolveConnectionKey(a) .Should().NotBe(RabbitMQComponent.ResolveConnectionKey(b)); } [Fact] public void ResolveKey_DifferentInlineVHosts_ProduceDistinctKeys() { var a = OptionsFromUri("rabbitmq://q?host=h&username=u&virtualHost=/prod"); var b = OptionsFromUri("rabbitmq://q?host=h&username=u&virtualHost=/dev"); RabbitMQComponent.ResolveConnectionKey(a) .Should().NotBe(RabbitMQComponent.ResolveConnectionKey(b)); } [Fact] public void Component_DisposeAsync_OnEmptyPool_DoesNotThrow() { var component = new RabbitMQComponent(); var act = async () => await component.DisposeAsync(); act.Should().NotThrowAsync(); } [Theory] [InlineData("heartbeat=10")] [InlineData("connectionTimeout=5")] [InlineData("socketReadTimeout=5")] [InlineData("socketWriteTimeout=5")] [InlineData("continuationTimeout=5")] [InlineData("automaticRecovery=false")] [InlineData("topologyRecoveryEnabled=false")] [InlineData("recoveryInterval=30")] [InlineData("clientName=billing")] [InlineData("password=other")] public void ResolveKey_an_endpoint_with_other_connection_settings_gets_its_own_connection(string setting) { // The first endpoint must not decide the connection of the second: a shared connection has one set of settings. var plain = RabbitMQComponent.ResolveConnectionKey(OptionsFromUri("rabbitmq://q?host=h&username=alice")); var other = RabbitMQComponent.ResolveConnectionKey(OptionsFromUri($"rabbitmq://q?host=h&username=alice&{setting}")); other.Should().NotBe(plain); } [Fact] public void ResolveKey_carries_no_password_in_clear() { var key = RabbitMQComponent.ResolveConnectionKey(OptionsFromUri("rabbitmq://q?host=h&username=alice&password=s3cr3t-value")); key.Should().NotContain("s3cr3t-value", "the key is written to the log when the connection opens"); } }