diff --git a/tests/UiPath.Caching.Tests/Redis/ProfiledCommandExtensionsIntegrationTests.cs b/tests/UiPath.Caching.Tests/Redis/ProfiledCommandExtensionsIntegrationTests.cs new file mode 100644 index 0000000..5f902d3 --- /dev/null +++ b/tests/UiPath.Caching.Tests/Redis/ProfiledCommandExtensionsIntegrationTests.cs @@ -0,0 +1,38 @@ +using StackExchange.Redis; +using StackExchange.Redis.Profiling; +using UiPath.Caching.Redis; + +namespace UiPath.Caching.Tests.Redis; + +[Collection("RedisIntegration")] +[Trait("Category", "Integration")] +public class ProfiledCommandExtensionsIntegrationTests(RedisContainerFixture fixture) +{ + [Fact] + public async Task GetStatement_IncludesKey_FromLiveProfiledCommand() + { + Assert.SkipUnless(fixture.Enabled, "Set RUN_REDIS_INTEGRATION_TESTS=1 (Docker required) to run."); + + await using var multiplexer = await ConnectionMultiplexer.ConnectAsync(fixture.ConnectionString); + var database = multiplexer.GetDatabase(); + await database.PingAsync(); + + var session = new ProfilingSession(); + multiplexer.RegisterProfiler(() => session); + + var key = $"profiled-{Guid.NewGuid():N}"; + await database.StringSetAsync(key, "value"); + await database.StringGetAsync(key); + + var commands = session.FinishProfiling().ToList(); + + var keyed = commands.FirstOrDefault(c => + (string.Equals(c.Command, "SET", StringComparison.Ordinal) || string.Equals(c.Command, "GET", StringComparison.Ordinal)) + && c.GetStatement().Contains(key, StringComparison.Ordinal)); + + keyed.Should().NotBeNull(); + keyed!.GetStatement().Should().NotBe(keyed.GetCommandName()); + keyed.GetStatement().Should().StartWith(keyed.Command).And.Contain(key); + keyed.GetTarget().Should().NotBeNullOrEmpty().And.Contain(":"); + } +} diff --git a/tests/UiPath.Caching.Tests/Redis/RedisConnectorIntegrationTests.cs b/tests/UiPath.Caching.Tests/Redis/RedisConnectorIntegrationTests.cs index 3d49518..a0ed080 100644 --- a/tests/UiPath.Caching.Tests/Redis/RedisConnectorIntegrationTests.cs +++ b/tests/UiPath.Caching.Tests/Redis/RedisConnectorIntegrationTests.cs @@ -65,5 +65,7 @@ public async Task GetMasterPhysicalConnectionMetrics_ReturnsData_OnLiveConnectio var metrics = connector.GetMasterPhysicalConnectionMetrics(multiplexer); metrics.Should().NotBeNull(); + metrics!.EndPoint.Should().BeOneOf(multiplexer.GetEndPoints()); + metrics.AwaitingResponseCount.Should().BeGreaterThanOrEqualTo(0); } }