Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ internal sealed partial class ServerTestHost : CommonHost, IServerTestHost, IDis
private readonly IMessageHandlerFactory _messageHandlerFactory;
private readonly TestFrameworkManager _testFrameworkManager;
private readonly TestHostManager _testSessionManager;
private readonly ServerTelemetry _telemetryService;
private readonly IAsyncMonitor _messageMonitor;
private readonly IEnvironment _environment;
private readonly ILogger<ServerTestHost> _logger;
Expand Down Expand Up @@ -66,7 +65,6 @@ public ServerTestHost(
_messageHandlerFactory = messageHandlerFactory;
_testFrameworkManager = testFrameworkManager;
_testSessionManager = testSessionManager;
_telemetryService = new ServerTelemetry(this);
_clientToServerRequests = new();
_serverToClientRequests = new();

Expand Down Expand Up @@ -571,7 +569,7 @@ await ExecuteRequestAsync(
requestExecuteStart, (DateTimeOffset)requestExecuteStop,
testNodeUpdateProcessor.GetTestNodeStatistics().TotalDiscoveredTests);

await _telemetryService.LogEventAsync(isRunRequest ? TelemetryEvents.TestsRunEventName : TelemetryEvents.TestsDiscoveryEventName, metadata, cancellationToken).ConfigureAwait(false);
await ServiceProvider.GetTelemetryCollector().LogEventAsync(isRunRequest ? TelemetryEvents.TestsRunEventName : TelemetryEvents.TestsDiscoveryEventName, metadata, cancellationToken).ConfigureAwait(false);

return isRunRequest
? new RunResponseArgs([.. testNodeUpdateProcessor.Artifacts])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ private async Task<IHost> BuildServerTestHostAsync(BuildContext context, NamedPi
(TestFrameworkManager)TestFramework!,
(TestHostManager)TestHost);

// Register ServerTelemetry in the service provider so that all telemetry events in server mode
// are forwarded to the client via JSON-RPC. This replaces the NopTelemetryService registered
// earlier in SetupCommonServicesAsync.
context.ServiceProvider.ReplaceService<ITelemetryCollector>(new ServerTelemetry(serverTestHost));
Comment thread
Evangelink marked this conversation as resolved.
Resolved

#pragma warning disable CA1416 // Preserve existing browser behavior while splitting the method.
IHost actualTestHost = testControllerConnection is not null
? new TestHostControlledHost(testControllerConnection, serverTestHost, context.TestApplicationCancellationTokenSource.CancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ public bool TryAddService(object service)
return true;
}

/// <summary>
/// Replaces the first registered service instance that is an instance of <typeparamref name="T"/> with the new service.
/// If no such service is found, the new service is added at the end of the list.
/// </summary>
/// <typeparam name="T">The type of service to replace.</typeparam>
internal void ReplaceService<T>(T newService)
where T : class
{
ArgumentGuard.Ensure(
newService is not ITestFramework || AllowTestAdapterFrameworkRegistration,
nameof(newService),
PlatformResources.ServiceProviderShouldNotRegisterTestFramework);

int index = _services.FindIndex(s => s is T);
if (index >= 0)
{
_services[index] = newService;
}
else
{
_services.Add(newService);
}
Comment thread
Evangelink marked this conversation as resolved.
Resolved
}
Comment thread
Evangelink marked this conversation as resolved.
Resolved

public IEnumerable<object> GetServicesInternal(
Type serviceType,
bool stopAtFirst = false,
Expand Down
Loading