Skip to content

Commit

Permalink
Temporary disable full post processing in design mode (#3429)
Browse files Browse the repository at this point in the history
Temporary disable full post processing in design mode
  • Loading branch information
MarcoRossignoli authored Mar 2, 2022
1 parent 90b64b7 commit 98098ad
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static FeatureFlag()
{
FeatureFlags.Add(ARTIFACTS_POSTPROCESSING, true);
FeatureFlags.Add(ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX, false);
FeatureFlags.Add(FORCE_DATACOLLECTORS_ATTACHMENTPROCESSORS, false);
}

// Added for artifact porst-processing, it enable/disable the post processing.
Expand All @@ -31,6 +32,9 @@ static FeatureFlag()
// Added in 17.2-preview 7.0-preview
public static string ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX = VSTEST_FEATURE + "_" + "ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX";

// Temporary used to allow tests to work
public static string FORCE_DATACOLLECTORS_ATTACHMENTPROCESSORS = VSTEST_FEATURE + "_" + "FORCE_DATACOLLECTORS_ATTACHMENTPROCESSORS";

// For now we're checking env var.
// We could add it also to some section inside the runsettings.
public bool IsEnabled(string featureName) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

internal interface IRunSettingsHelper
{
bool IsDefaultTargetArchitecture { get; set; }

bool IsDesignMode { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ internal class RunSettingsHelper : IRunSettingsHelper
/// --arch or runsettings file or -- RunConfiguration.TargetPlatform=arch
/// </summary>
public bool IsDefaultTargetArchitecture { get; set; } = true;

/// <summary>
/// True indicates the test run is started from an Editor or IDE.
/// Defaults to false.
/// </summary>
public bool IsDesignMode { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

#nullable disable

Expand All @@ -28,51 +29,60 @@ public DataCollectorAttachmentProcessor[] Create(InvokedDataCollector[] invokedD
{
IDictionary<string, Tuple<string, IDataCollectorAttachmentProcessor>> datacollectorsAttachmentsProcessors = new Dictionary<string, Tuple<string, IDataCollectorAttachmentProcessor>>();

if (invokedDataCollectors?.Length > 0)

// Temporary disabled in design mode.
// We have an issue when the collector is found inside bin folder/subfolder of the user in case of VS.
// Usually collector are loaded from nuget package or visual studio special folders, but if a user for some reason run `dotnet publish`
// and after run the datacollector with the attachment processor we're loading 'published' version and no more nuget one.
// This led to file locking that prevents further `dotnet publish` and maybe build.
if (!RunSettingsHelper.Instance.IsDesignMode || FeatureFlag.Instance.IsEnabled(FeatureFlag.FORCE_DATACOLLECTORS_ATTACHMENTPROCESSORS))
{
// We order files by filename descending so in case of the same collector from the same nuget but with different versions, we'll run the newer version.
// i.e. C:\Users\xxx\.nuget\packages\coverlet.collector
// /3.0.2
// /3.0.3
// /3.1.0
foreach (var invokedDataCollector in invokedDataCollectors.OrderByDescending(d => d.FilePath))
if (invokedDataCollectors?.Length > 0)
{
// We'll merge using only one AQN in case of more "same processors" in different assembly.
if (!invokedDataCollector.HasAttachmentProcessor)
{
continue;
}

EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: Analyzing data collector attachment processor Uri: {invokedDataCollector.Uri} AssemblyQualifiedName: {invokedDataCollector.AssemblyQualifiedName} FilePath: {invokedDataCollector.FilePath} HasAttachmentProcessor: {invokedDataCollector.HasAttachmentProcessor}");

// We cache extension locally by file path
var dataCollectorExtensionManager = DataCollectorExtensionManagerCache.GetOrAdd(invokedDataCollector.FilePath, DataCollectorExtensionManager.Create(invokedDataCollector.FilePath, true, TestSessionMessageLogger.Instance));
var dataCollectorExtension = dataCollectorExtensionManager.TryGetTestExtension(invokedDataCollector.Uri);
if (dataCollectorExtension?.Metadata.HasAttachmentProcessor == true)
// We order files by filename descending so in case of the same collector from the same nuget but with different versions, we'll run the newer version.
// i.e. C:\Users\xxx\.nuget\packages\coverlet.collector
// /3.0.2
// /3.0.3
// /3.1.0
foreach (var invokedDataCollector in invokedDataCollectors.OrderByDescending(d => d.FilePath))
{
Type attachmentProcessorType = ((DataCollectorConfig)dataCollectorExtension.TestPluginInfo).AttachmentsProcessorType;
IDataCollectorAttachmentProcessor dataCollectorAttachmentProcessorInstance = null;
try
// We'll merge using only one AQN in case of more "same processors" in different assembly.
if (!invokedDataCollector.HasAttachmentProcessor)
{
dataCollectorAttachmentProcessorInstance = TestPluginManager.CreateTestExtension<IDataCollectorAttachmentProcessor>(attachmentProcessorType);
EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: Creation of collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}' from file '{invokedDataCollector.FilePath}' succeded");
continue;
}
catch (Exception ex)

EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: Analyzing data collector attachment processor Uri: {invokedDataCollector.Uri} AssemblyQualifiedName: {invokedDataCollector.AssemblyQualifiedName} FilePath: {invokedDataCollector.FilePath} HasAttachmentProcessor: {invokedDataCollector.HasAttachmentProcessor}");

// We cache extension locally by file path
var dataCollectorExtensionManager = DataCollectorExtensionManagerCache.GetOrAdd(invokedDataCollector.FilePath, DataCollectorExtensionManager.Create(invokedDataCollector.FilePath, true, TestSessionMessageLogger.Instance));
var dataCollectorExtension = dataCollectorExtensionManager.TryGetTestExtension(invokedDataCollector.Uri);
if (dataCollectorExtension?.Metadata.HasAttachmentProcessor == true)
{
EqtTrace.Error($"DataCollectorAttachmentsProcessorsFactory: Failed during the creation of data collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}'\n{ex}");
logger?.SendMessage(TestMessageLevel.Error, $"DataCollectorAttachmentsProcessorsFactory: Failed during the creation of data collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}'\n{ex}");
}
Type attachmentProcessorType = ((DataCollectorConfig)dataCollectorExtension.TestPluginInfo).AttachmentsProcessorType;
IDataCollectorAttachmentProcessor dataCollectorAttachmentProcessorInstance = null;
try
{
dataCollectorAttachmentProcessorInstance = TestPluginManager.CreateTestExtension<IDataCollectorAttachmentProcessor>(attachmentProcessorType);
EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: Creation of collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}' from file '{invokedDataCollector.FilePath}' succeded");
}
catch (Exception ex)
{
EqtTrace.Error($"DataCollectorAttachmentsProcessorsFactory: Failed during the creation of data collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}'\n{ex}");
logger?.SendMessage(TestMessageLevel.Error, $"DataCollectorAttachmentsProcessorsFactory: Failed during the creation of data collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}'\n{ex}");
}

if (dataCollectorAttachmentProcessorInstance != null && !datacollectorsAttachmentsProcessors.ContainsKey(attachmentProcessorType.AssemblyQualifiedName))
if (dataCollectorAttachmentProcessorInstance != null && !datacollectorsAttachmentsProcessors.ContainsKey(attachmentProcessorType.AssemblyQualifiedName))
{
datacollectorsAttachmentsProcessors.Add(attachmentProcessorType.AssemblyQualifiedName, new Tuple<string, IDataCollectorAttachmentProcessor>(dataCollectorExtension.Metadata.FriendlyName, dataCollectorAttachmentProcessorInstance));
EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: Collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}' from file '{invokedDataCollector.FilePath}' added to the 'run list'");
}
}
else
{
datacollectorsAttachmentsProcessors.Add(attachmentProcessorType.AssemblyQualifiedName, new Tuple<string, IDataCollectorAttachmentProcessor>(dataCollectorExtension.Metadata.FriendlyName, dataCollectorAttachmentProcessorInstance));
EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: Collector attachment processor '{attachmentProcessorType.AssemblyQualifiedName}' from file '{invokedDataCollector.FilePath}' added to the 'run list'");
EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: DataCollectorExtension not found for uri '{invokedDataCollector.Uri}'");
}
}
else
{
EqtTrace.Info($"DataCollectorAttachmentsProcessorsFactory: DataCollectorExtension not found for uri '{invokedDataCollector.Uri}'");
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/vstest.console/Processors/PortArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;

Expand Down Expand Up @@ -143,6 +144,7 @@ public void Initialize(string argument)

_commandLineOptions.Port = portNumber;
_commandLineOptions.IsDesignMode = true;
RunSettingsHelper.Instance.IsDesignMode = true;
_designModeClient = _designModeInitializer?.Invoke(_commandLineOptions.ParentProcessId, _processHelper);
}

Expand Down
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 System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -32,6 +33,13 @@ public class CodeCoverageTests : CodeCoverageAcceptanceTestBase
private RunEventHandler _runEventHandler;
private TestRunAttachmentsProcessingEventHandler _testRunAttachmentsProcessingEventHandler;

static CodeCoverageTests()
{
#pragma warning disable RS0030 // Do not used banned APIs - We need it temporary
Environment.SetEnvironmentVariable("VSTEST_FEATURE_FORCE_DATACOLLECTORS_ATTACHMENTPROCESSORS", "1");
#pragma warning restore RS0030 // Do not used banned APIs - We need it temporary
}

private void Setup()
{
_vstestConsoleWrapper = GetVsTestConsoleWrapper(out _tempDirectory);
Expand Down

0 comments on commit 98098ad

Please sign in to comment.