Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only push output device messages to Test Explorer, don't push logs #4178

Merged
merged 32 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2d96954
Only push output device messages to Test Explorer, don't push logs
Youssef1313 Nov 27, 2024
1231ea9
Remove unused usings
Youssef1313 Nov 27, 2024
a3429b0
Adjust test expectation for the new behavior
Youssef1313 Nov 27, 2024
3b0d18d
Review comments
Youssef1313 Nov 28, 2024
0a7df37
Cleanup possibly redundant check
Youssef1313 Nov 28, 2024
f7d05a5
Always log something in before session
Youssef1313 Nov 28, 2024
e3299b8
Adjust
Youssef1313 Nov 29, 2024
13766b5
Fix assert back and TODO
Youssef1313 Nov 29, 2024
c714c07
Add test
Youssef1313 Nov 29, 2024
968c79b
Localize
Youssef1313 Nov 29, 2024
6767387
Fix test
Youssef1313 Nov 30, 2024
74da123
Address review comment
Youssef1313 Dec 2, 2024
5560e40
Refactor
Youssef1313 Dec 2, 2024
7874d42
Further cleanup
Youssef1313 Dec 2, 2024
a823ac0
Fix build errors
Youssef1313 Dec 2, 2024
f6d0c1b
Fix missing initialization
Youssef1313 Dec 2, 2024
7e7fb18
Merge branch 'main' into logging-improvements
Youssef1313 Dec 3, 2024
edf7751
Follow-up per recent changes
Youssef1313 Dec 3, 2024
b4bf543
Remove unused using
Youssef1313 Dec 3, 2024
1d355c2
Temporary restore `FormattedTextOutputDeviceDataBuilder`
Youssef1313 Dec 3, 2024
25dbaaf
Adjust
Youssef1313 Dec 3, 2024
adb40be
Progress
Youssef1313 Dec 3, 2024
7b778db
Merge branch 'main' into logging-improvements
Youssef1313 Dec 3, 2024
d7f4353
Merge branch 'logging-improvements' of https://github.com/Youssef1313…
Youssef1313 Dec 3, 2024
074227f
Forward some messages to output device (hence, to TE)
Youssef1313 Dec 3, 2024
870fb58
Cleanup
Youssef1313 Dec 3, 2024
09aad35
Remove unused using
Youssef1313 Dec 3, 2024
c2edd6a
Decouple IOutputDevice from IPlatformOutputDevice
Youssef1313 Dec 3, 2024
59fd67a
Avoid async void
Youssef1313 Dec 3, 2024
26964af
Fix race
Youssef1313 Dec 4, 2024
39971bd
Address review comments
Youssef1313 Dec 4, 2024
e3e2907
Move comment to server mode output device
Youssef1313 Dec 4, 2024
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
19 changes: 10 additions & 9 deletions src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.OutputDevice;
using Microsoft.Testing.Platform.Requests;
using Microsoft.Testing.Platform.ServerMode;
using Microsoft.Testing.Platform.Services;
Expand Down Expand Up @@ -118,13 +119,6 @@ protected override async Task<int> InternalRunAsync()
await _logger.LogDebugAsync("Starting server mode");
_messageHandler = await _messageHandlerFactory.CreateMessageHandlerAsync(_testApplicationCancellationTokenSource.CancellationToken);

// Initialize the ServerLoggerForwarderProvider, it can be null if diagnostic is disabled.
ServerLoggerForwarderProvider? serviceLoggerForwarder = ServiceProvider.GetService<ServerLoggerForwarderProvider>();
if (serviceLoggerForwarder is not null)
{
await serviceLoggerForwarder.InitializeAsync(this);
}

await HandleMessagesAsync();

(_messageHandler as IDisposable)?.Dispose();
Expand Down Expand Up @@ -450,13 +444,20 @@ private async Task<ResponseArgsBase> ExecuteRequestAsync(RequestArgsBase args, s

DateTimeOffset adapterLoadStart = _clock.UtcNow;

IPlatformOutputDevice outputDevice = ServiceProvider.GetRequiredService<IPlatformOutputDevice>();
// TODO: What if some one wants to have their own output device that's also compatible with server mode in IDE?
if (outputDevice is ServerModePerCallOutputDevice serverModePerCallOutputDevice)
{
await serverModePerCallOutputDevice.InitializeAsync(this);
}

// Build the per request adapter
ITestFramework perRequestTestFramework = await _buildTestFrameworkAsync(new(
ITestFramework perRequestTestFramework = await _buildTestFrameworkAsync(new TestFrameworkBuilderData(
perRequestServiceProvider,
requestFactory,
invoker,
filterFactory,
new ServerModePerCallOutputDevice(),
outputDevice,
[testNodeUpdateProcessor],
_testFrameworkManager,
_testSessionManager,
Expand Down
24 changes: 10 additions & 14 deletions src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ public async Task<ITestHost> BuildAsync(
LoggerFactoryProxy loggerFactoryProxy = new();
serviceProvider.TryAddService(loggerFactoryProxy);

// Add output display proxy, needed by command line manager.
// We don't add to the service right now because we need special treatment between console/server mode.
IPlatformOutputDevice platformOutputDevice = ((PlatformOutputDeviceManager)OutputDisplay).Build(serviceProvider);

// Add Terminal options provider
CommandLine.AddProvider(() => new TerminalTestReporterCommandLineOptionsProvider());

Expand All @@ -210,6 +206,16 @@ public async Task<ITestHost> BuildAsync(
// Set the concrete command line options to the proxy.
commandLineOptionsProxy.SetCommandLineOptions(commandLineHandler);

bool hasServerFlag = commandLineHandler.TryGetOptionArgumentList(PlatformCommandLineProvider.ServerOptionKey, out string[]? protocolName);
bool isJsonRpcProtocol = protocolName is null || protocolName.Length == 0 || protocolName[0].Equals(PlatformCommandLineProvider.JsonRpcProtocolName, StringComparison.OrdinalIgnoreCase);

// TODO(youssef): In what way the output device is needed by command line manager?
// TODO(youssef): Building the platform output device depends on whether we are running server mode in TE or not.
// TODO(youssef): So we need to now create commandline handler first. :(
// Add output display proxy, needed by command line manager.
// We don't add to the service right now because we need special treatment between console/server mode.
IPlatformOutputDevice platformOutputDevice = ((PlatformOutputDeviceManager)OutputDisplay).Build(serviceProvider, hasServerFlag && isJsonRpcProtocol);

// Add FileLoggerProvider if needed
if (loggingState.FileLoggerProvider is not null)
{
Expand All @@ -219,16 +225,6 @@ public async Task<ITestHost> BuildAsync(
// Get the command line options
ICommandLineOptions commandLineOptions = serviceProvider.GetCommandLineOptions();

// Register the server mode log forwarder if needed. We follow the console --diagnostic behavior.
bool hasServerFlag = commandLineHandler.TryGetOptionArgumentList(PlatformCommandLineProvider.ServerOptionKey, out string[]? protocolName);
bool isJsonRpcProtocol = protocolName is null || protocolName.Length == 0 || protocolName[0].Equals(PlatformCommandLineProvider.JsonRpcProtocolName, StringComparison.OrdinalIgnoreCase);
if (hasServerFlag && isJsonRpcProtocol)
{
ServerLoggerForwarderProvider serverLoggerProxy = new(loggingState.LogLevel, serviceProvider);
serviceProvider.AddService(serverLoggerProxy);
Logging.AddProvider((logLevel, services) => serverLoggerProxy);
}

// Build the logger factory.
ILoggerFactory loggerFactory = await ((LoggingManager)Logging).BuildAsync(serviceProvider, loggingState.LogLevel, systemMonitor);

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.ServerMode;
using Microsoft.Testing.Platform.Services;

namespace Microsoft.Testing.Platform.OutputDevice;
Expand All @@ -15,15 +16,19 @@ public void SetPlatformOutputDevice(Func<IServiceProvider, IPlatformOutputDevice
_platformOutputDeviceFactory = platformOutputDeviceFactory;
}

public IPlatformOutputDevice Build(ServiceProvider serviceProvider)
public IPlatformOutputDevice Build(ServiceProvider serviceProvider, bool useServerModeOutputDevice)
{
if (_platformOutputDeviceFactory is not null)
{
// TODO: SetPlatformOutputDevice isn't public yet.
// Before exposing it, do we want to pass the "useServerModeOutputDevice" info to it?
IPlatformOutputDevice platformOutputDevice = _platformOutputDeviceFactory(serviceProvider);
return platformOutputDevice;
}

return GetDefaultTerminalOutputDevice(serviceProvider);
return useServerModeOutputDevice
? new ServerModePerCallOutputDevice(serviceProvider)
: GetDefaultTerminalOutputDevice(serviceProvider);
}

public static TerminalOutputDevice GetDefaultTerminalOutputDevice(ServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,13 @@ Takes one argument as string in the format &lt;value&gt;[h|m|s] where 'value' is
<data name="ConfigurationFileNotFound" xml:space="preserve">
<value>The configuration file '{0}' specified with '--config-file' could not be found.</value>
</data>
</root>
<data name="StartingTestSession" xml:space="preserve">
<value>Starting test session.</value>
</data>
<data name="StartingTestSessionWithLogFilePath" xml:space="preserve">
<value>Starting test session. The log file path is '{0}'.</value>
</data>
<data name="FinishedTestSession" xml:space="preserve">
<value>Finished test session.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@
<target state="translated">selhalo s {0} upozorněním(i).</target>
<note />
</trans-unit>
<trans-unit id="FinishedTestSession">
<source>Finished test session.</source>
<target state="new">Finished test session.</target>
<note />
</trans-unit>
<trans-unit id="ForTest">
<source>For test</source>
<target state="translated">Pro testování</target>
Expand Down Expand Up @@ -688,6 +693,16 @@ Může mít jenom jeden argument jako řetězec ve formátu &lt;value&gt;[h|m|s]
<target state="translated">Spouští se server. Naslouchání na portu {0}</target>
<note />
</trans-unit>
<trans-unit id="StartingTestSession">
<source>Starting test session.</source>
<target state="new">Starting test session.</target>
<note />
</trans-unit>
<trans-unit id="StartingTestSessionWithLogFilePath">
<source>Starting test session. The log file path is '{0}'.</source>
<target state="new">Starting test session. The log file path is '{0}'.</target>
<note />
</trans-unit>
<trans-unit id="TEstExecutionFilterFactoryFactoryAlreadySetErrorMessage">
<source>An 'ITestExecutionFilterFactory' factory is already set</source>
<target state="translated">Objekt pro vytváření ITestExecutionFilterFactory je už nastavený.</target>
Expand Down
Loading