Path: redb-route/tests/redb.Route.Tests.SignalR/SignalRTelemetrySmokeTests.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.SignalR/SignalRTelemetrySmokeTests.cs
----
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.SignalR;
using redb.Route.Telemetry;
using redb.Route.Tests.Shared;
namespace redb.Route.Tests.SignalR;
/// Smoke test for the P1 transport span opened by (Server mode).
public sealed class SignalRTelemetrySmokeTests : IAsyncLifetime
{
private int _port;
private SignalRConsumer? _consumer;
private SignalRProducer? _producer;
public Task InitializeAsync()
{
_port = GetFreePort();
return Task.CompletedTask;
}
public async Task DisposeAsync()
{
if (_producer is not null) await _producer.Stop();
if (_consumer is not null) await _consumer.Stop();
}
[Fact]
public async Task SignalRProducer_EmitsTransportSpanWithMessagingTags()
{
var component = new SignalRComponent();
var path = $"/127.0.0.1:{_port}/hub";
// Consumer (server)
var cUri = new EndpointUri("signalr", path, $"signalr:{path}", new Dictionary());
var cEndpoint = (SignalREndpoint)component.CreateEndpoint(cUri);
var processor = Substitute.For();
_consumer = new SignalRConsumer(cEndpoint, processor, cEndpoint.EndpointOptions);
await _consumer.Start();
// Producer (server mode)
var pPars = new Dictionary { ["mode"] = "Server", ["method"] = "Send" };
var pUri = new EndpointUri("signalr", path, $"signalr:{path}", pPars);
var pEndpoint = (SignalREndpoint)component.CreateEndpoint(pUri);
_producer = (SignalRProducer)pEndpoint.CreateProducer();
await _producer.Start();
using var capture = new SpanCapture(); // this test's spans only
await _producer.Process(new Exchange(new Message("hello")));
var activities = capture.Spans;
activities.Should().NotBeEmpty();
var activity = activities.First();
activity.Source.Name.Should().Be(RouteActivitySource.SourceName);
activity.Kind.Should().Be(ActivityKind.Producer);
activity.GetTagItem("messaging.system").Should().Be("signalr");
activity.GetTagItem("redb.route.endpoint").Should().NotBeNull();
}
private static int GetFreePort() => global::redb.Route.Tests.Shared.TestPorts.Next();
}