Skip to content

Commit

Permalink
Move load failure messages from DiaSession and friends to internal di…
Browse files Browse the repository at this point in the history
…agnostics messages
  • Loading branch information
bradwilson committed Oct 15, 2023
1 parent 3761c16 commit 097b605
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions src/xunit.runner.visualstudio/Utility/DiaSessionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ class DiaSessionWrapper : IDisposable
#endif
readonly DiaSessionWrapperHelper? helper;
readonly DiaSession? session;
readonly DiagnosticMessageSink diagnosticMessageSink;
readonly DiagnosticMessageSink internalDiagnosticMessageSink;

public DiaSessionWrapper(
string assemblyFileName,
DiagnosticMessageSink diagnosticMessageSink)
DiagnosticMessageSink internalDiagnosticMessageSink)
{
this.diagnosticMessageSink = Guard.ArgumentNotNull(diagnosticMessageSink);
this.internalDiagnosticMessageSink = Guard.ArgumentNotNull(internalDiagnosticMessageSink);

try
{
session = new DiaSession(assemblyFileName);
}
catch (Exception ex)
{
diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception creating DiaSession: {ex}"));
internalDiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception creating DiaSession: {ex}"));
}

try
Expand All @@ -48,7 +48,7 @@ public DiaSessionWrapper(
}
catch (Exception ex)
{
diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception creating DiaSessionWrapperHelper: {ex}"));
internalDiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception creating DiaSessionWrapperHelper: {ex}"));
}
}

Expand All @@ -66,7 +66,7 @@ public DiaSessionWrapper(
}
catch (Exception ex)
{
diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception getting source mapping for {typeName}.{methodName}: {ex}"));
internalDiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception getting source mapping for {typeName}.{methodName}: {ex}"));
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class VisualStudioSourceInformationProvider : LongLivedMarshalByRefObject
/// Initializes a new instance of the <see cref="VisualStudioSourceInformationProvider" /> class.
/// </summary>
/// <param name="assemblyFileName">The assembly file name.</param>
/// <param name="diagnosticMessageSink">The message sink to send internal diagnostic messages to.</param>
/// <param name="internalDiagnosticMessageSink">The message sink to send internal diagnostic messages to.</param>
public VisualStudioSourceInformationProvider(
string assemblyFileName,
DiagnosticMessageSink diagnosticMessageSink)
DiagnosticMessageSink internalDiagnosticMessageSink)
{
session = new DiaSessionWrapper(assemblyFileName, diagnosticMessageSink);
session = new DiaSessionWrapper(assemblyFileName, internalDiagnosticMessageSink);
}

/// <inheritdoc/>
Expand Down
42 changes: 21 additions & 21 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,21 @@ void DiscoverTests<TVisitor>(
{
RemotingUtility.CleanUpRegisteredChannels();

var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false);
var internalDiagnosticsSinkLocal = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false);
using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsSinkLocal));

using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink));
foreach (var assemblyFileNameCanBeWithoutAbsolutePath in sources)
{
var assembly = new XunitProjectAssembly { AssemblyFilename = GetAssemblyFileName(assemblyFileNameCanBeWithoutAbsolutePath) };
runSettings.CopyTo(assembly.Configuration);

var fileName = Path.GetFileNameWithoutExtension(assembly.AssemblyFilename);
var shadowCopy = assembly.Configuration.ShadowCopyOrDefault;
var diagnosticSink = DiagnosticMessageSink.ForDiagnostics(logger, fileName, assembly.Configuration.DiagnosticMessagesOrDefault);
var diagnosticsSinkLocal = DiagnosticMessageSink.ForDiagnostics(logger, fileName, assembly.Configuration.DiagnosticMessagesOrDefault);
var appDomain = assembly.Configuration.AppDomain ?? AppDomainDefaultBehavior;

using var sourceInformationProvider = new VisualStudioSourceInformationProvider(assembly.AssemblyFilename, diagnosticSink);
using var controller = new XunitFrontController(appDomain, assembly.AssemblyFilename, shadowCopy: shadowCopy, sourceInformationProvider: sourceInformationProvider, diagnosticMessageSink: MessageSinkAdapter.Wrap(diagnosticSink));
using var sourceInformationProvider = new VisualStudioSourceInformationProvider(assembly.AssemblyFilename, internalDiagnosticsSinkLocal);
using var controller = new XunitFrontController(appDomain, assembly.AssemblyFilename, shadowCopy: shadowCopy, sourceInformationProvider: sourceInformationProvider, diagnosticMessageSink: MessageSinkAdapter.Wrap(diagnosticsSinkLocal));
if (!DiscoverTestsInSource(controller, logger, testPlatformContext, runSettings, visitorFactory, visitComplete, assembly))
break;
}
Expand Down Expand Up @@ -384,18 +384,16 @@ void RunTests(
var parallelizeAssemblies = runInfos.All(runInfo => runInfo.Assembly.Configuration.ParallelizeAssemblyOrDefault);
var reporter = GetRunnerReporter(logger, runSettings, runInfos.Select(ari => ari.Assembly.AssemblyFilename).ToList());
using var reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(reporter.CreateMessageHandler(new VisualStudioRunnerLogger(logger)));
using var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false);
using var internalDiagnosticsSinkLocal = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false);
using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsSinkLocal));

using (AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink)))
{
if (parallelizeAssemblies)
runInfos
.Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo))
.ToList()
.ForEach(@event => @event.WaitOne());
else
runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo));
}
if (parallelizeAssemblies)
runInfos
.Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo))
.ToList()
.ForEach(@event => @event.WaitOne());
else
runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -426,10 +424,12 @@ void RunTestsInAssembly(
var appDomain = configuration.AppDomain ?? AppDomainDefaultBehavior;
var longRunningSeconds = configuration.LongRunningTestSecondsOrDefault;

var diagnosticSink = DiagnosticMessageSink.ForDiagnostics(logger, assemblyDisplayName, runInfo.Assembly.Configuration.DiagnosticMessagesOrDefault);
var diagnosticMessageSink = MessageSinkAdapter.Wrap(diagnosticSink);
using var sourceInformationProvider = new VisualStudioSourceInformationProvider(assemblyFileName, diagnosticSink);
using var controller = new XunitFrontController(appDomain, assemblyFileName, shadowCopy: shadowCopy, sourceInformationProvider: sourceInformationProvider, diagnosticMessageSink: diagnosticMessageSink);
var diagnosticsSinkLocal = DiagnosticMessageSink.ForDiagnostics(logger, assemblyDisplayName, runInfo.Assembly.Configuration.DiagnosticMessagesOrDefault);
var diagnosticsSinkRemote = MessageSinkAdapter.Wrap(diagnosticsSinkLocal);
var internalDiagnosticsSinkLocal = DiagnosticMessageSink.ForInternalDiagnostics(logger, runInfo.Assembly.Configuration.InternalDiagnosticMessagesOrDefault);

using var sourceInformationProvider = new VisualStudioSourceInformationProvider(assemblyFileName, internalDiagnosticsSinkLocal);
using var controller = new XunitFrontController(appDomain, assemblyFileName, shadowCopy: shadowCopy, sourceInformationProvider: sourceInformationProvider, diagnosticMessageSink: diagnosticsSinkRemote);
var testCasesMap = new Dictionary<string, TestCase>();
var testCases = new List<ITestCase>();
if (runInfo.TestCases is null || !runInfo.TestCases.Any())
Expand Down Expand Up @@ -543,7 +543,7 @@ void RunTestsInAssembly(
using var vsExecutionSink = new VsExecutionSink(reporterMessageHandler, frameworkHandle, logger, testCasesMap, () => cancelled);
IExecutionSink resultsSink = vsExecutionSink;
if (longRunningSeconds > 0)
resultsSink = new DelegatingLongRunningTestDetectionSink(resultsSink, TimeSpan.FromSeconds(longRunningSeconds), diagnosticSink);
resultsSink = new DelegatingLongRunningTestDetectionSink(resultsSink, TimeSpan.FromSeconds(longRunningSeconds), diagnosticsSinkLocal);
if (configuration.FailSkipsOrDefault)
resultsSink = new DelegatingFailSkipSink(resultsSink);

Expand Down

0 comments on commit 097b605

Please sign in to comment.