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

Add artifacts post processing #24012

Merged
merged 20 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e34377d
add artifacts post processing
MarcoRossignoli Feb 18, 2022
39697de
add post processing errors
MarcoRossignoli Feb 18, 2022
1f156bc
cleanup
MarcoRossignoli Feb 18, 2022
e850575
fix tests
MarcoRossignoli Feb 18, 2022
fb0a59a
fix tests round 2
MarcoRossignoli Feb 18, 2022
5add2a1
fix tests round 3
MarcoRossignoli Feb 18, 2022
4888bdd
Update src/Assets/TestProjects/VSTestDataCollectorSample/AttachmentPr…
MarcoRossignoli Feb 18, 2022
d0374e1
Update src/Assets/TestProjects/VSTestDataCollectorSampleNoMerge/Attac…
MarcoRossignoli Feb 18, 2022
b69187a
Update src/Cli/dotnet/commands/dotnet-test/Program.cs
MarcoRossignoli Feb 18, 2022
17aa205
Update src/Cli/dotnet/commands/dotnet-test/VSTestTrace.cs
MarcoRossignoli Feb 18, 2022
abab472
Update src/Cli/dotnet/commands/dotnet-test/Program.cs
MarcoRossignoli Feb 18, 2022
a5ee5e9
Update src/Cli/dotnet/commands/dotnet-test/VSTestFeatureFlag.cs
MarcoRossignoli Feb 18, 2022
d52324b
Update src/Tests/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsArtifa…
MarcoRossignoli Feb 18, 2022
addb2d3
Update src/Cli/dotnet/commands/dotnet-test/VSTestFeatureFlag.cs
MarcoRossignoli Feb 18, 2022
abac772
Update src/Tests/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsArtifa…
MarcoRossignoli Feb 18, 2022
fbd09d0
address PR feedback
MarcoRossignoli Feb 18, 2022
aba9652
rename test
MarcoRossignoli Feb 18, 2022
cfd8f3b
cleanup namespace
MarcoRossignoli Feb 18, 2022
894fc75
refactoring, address PR feedback
MarcoRossignoli Feb 19, 2022
f07bff6
fix tests round 4
MarcoRossignoli Feb 20, 2022
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
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkPackageVersion)" />
</ItemGroup>

<ItemGroup>
<!-- Microsoft.NET.Test.Sdk package includes source files which shouldn't be automatically included. -->
<!-- Excluding those -->
<Compile Remove="pkgs\Microsoft.NET.Test.Sdk\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AttachmentProcessorDataCollector
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

internal class ExtensionInfo
{
public const string ExtensionType = "DataCollector";
public const string ExtensionIdentifier = "my://sample/datacollector";
}

[DataCollectorFriendlyName("SampleDataCollector")]
[DataCollectorTypeUri(ExtensionInfo.ExtensionIdentifier)]
[DataCollectorAttachmentProcessor(typeof(SampleDataCollectorAttachmentProcessor))]
public class SampleDataCollectorV2 : SampleDataCollectorV1 { }

[DataCollectorFriendlyName("SampleDataCollector")]
[DataCollectorTypeUri(ExtensionInfo.ExtensionIdentifier)]
public class SampleDataCollectorV1 : DataCollector
{
private DataCollectionSink _dataCollectionSink;
private DataCollectionEnvironmentContext _context;
private readonly string _tempDirectoryPath = Path.GetTempPath();

public override void Initialize(
XmlElement configurationElement,
DataCollectionEvents events,
DataCollectionSink dataSink,
DataCollectionLogger logger,
DataCollectionEnvironmentContext environmentContext)
{
events.SessionEnd += SessionEnded_Handler;
_dataCollectionSink = dataSink;
_context = environmentContext;
}

private void SessionEnded_Handler(object sender, SessionEndEventArgs e)
{
string tmpAttachment = Path.Combine(_tempDirectoryPath, Guid.NewGuid().ToString("N"), "DataCollectorAttachmentProcessor_1.txt");
Directory.CreateDirectory(Path.GetDirectoryName(tmpAttachment));
File.WriteAllText(tmpAttachment, $"SessionEnded_Handler_{Guid.NewGuid():N}");
_dataCollectionSink.SendFileAsync(_context.SessionDataCollectionContext, tmpAttachment, true);
}
}

public class SampleDataCollectorAttachmentProcessor : IDataCollectorAttachmentProcessor
{
public bool SupportsIncrementalProcessing => true;

public IEnumerable<Uri> GetExtensionUris()
=> new List<Uri>() { new Uri(ExtensionInfo.ExtensionIdentifier) };

public Task<ICollection<AttachmentSet>> ProcessAttachmentSetsAsync(XmlElement configurationElement, ICollection<AttachmentSet> attachments, IProgress<int> progressReporter, IMessageLogger logger, CancellationToken cancellationToken)
{
string finalFileName = configurationElement.FirstChild.InnerText;
StringBuilder stringBuilder = new StringBuilder();
string finalFolder = null;
foreach (var attachmentSet in attachments)
{
foreach (var attachment in attachmentSet.Attachments.OrderBy(f => f.Uri.AbsolutePath))
{
if (finalFolder is null)
{
finalFolder = Path.GetDirectoryName(attachment.Uri.AbsolutePath);
}

stringBuilder.AppendLine(File.ReadAllText(attachment.Uri.AbsolutePath).Trim());
}
}

File.WriteAllText(Path.Combine(finalFolder, finalFileName), stringBuilder.ToString());

List<AttachmentSet> mergedAttachment = new List<AttachmentSet>();
var mergedAttachmentSet = new AttachmentSet(new Uri("my://sample/datacollector"), "SampleDataCollector");
mergedAttachmentSet.Attachments.Add(UriDataAttachment.CreateFrom(Path.Combine(finalFolder, finalFileName), string.Empty));
mergedAttachment.Add(mergedAttachmentSet);

return Task.FromResult((ICollection<AttachmentSet>)new Collection<AttachmentSet>(mergedAttachment));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using AttachmentProcessorDataCollector;

using Microsoft.VisualStudio.TestPlatform;

[assembly: TestExtensionTypes(typeof(SampleDataCollectorV1))]
[assembly: TestExtensionTypesV2(ExtensionInfo.ExtensionType, ExtensionInfo.ExtensionIdentifier, typeof(SampleDataCollectorV1), 1, "futureUnused")]
[assembly: TestExtensionTypesV2(ExtensionInfo.ExtensionType, ExtensionInfo.ExtensionIdentifier, typeof(SampleDataCollectorV2), 2)]

namespace Microsoft.VisualStudio.TestPlatform
{
using System;

[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
internal sealed class TestExtensionTypesAttribute : Attribute
{
public TestExtensionTypesAttribute(params Type[] types)
{
Types = types;
}

public Type[] Types { get; }
}

[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
internal sealed class TestExtensionTypesV2Attribute : Attribute
{
public string ExtensionType { get; }
public string ExtensionIdentifier { get; }
public Type ExtensionImplementation { get; }
public int Version { get; }

public TestExtensionTypesV2Attribute(string extensionType, string extensionIdentifier, Type extensionImplementation, int version, string _ = null)
{
ExtensionType = extensionType;
ExtensionIdentifier = extensionIdentifier;
ExtensionImplementation = extensionImplementation;
Version = version;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkPackageVersion)" />
</ItemGroup>

<ItemGroup>
<!-- Microsoft.NET.Test.Sdk package includes source files which shouldn't be automatically included. -->
<!-- Excluding those -->
<Compile Remove="pkgs\Microsoft.NET.Test.Sdk\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AttachmentProcessorDataCollector
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

internal class ExtensionInfo
{
public const string ExtensionType = "DataCollector";
public const string ExtensionIdentifier = "my://sample/datacollector";
}

[DataCollectorFriendlyName("SampleDataCollector")]
[DataCollectorTypeUri(ExtensionInfo.ExtensionIdentifier)]
public class SampleDataCollectorV1 : DataCollector
{
private DataCollectionSink _dataCollectionSink;
private DataCollectionEnvironmentContext _context;
private readonly string _tempDirectoryPath = Path.GetTempPath();

public override void Initialize(
XmlElement configurationElement,
DataCollectionEvents events,
DataCollectionSink dataSink,
DataCollectionLogger logger,
DataCollectionEnvironmentContext environmentContext)
{
events.SessionEnd += SessionEnded_Handler;
_dataCollectionSink = dataSink;
_context = environmentContext;
}

private void SessionEnded_Handler(object sender, SessionEndEventArgs e)
{
string tmpAttachment = Path.Combine(_tempDirectoryPath, Guid.NewGuid().ToString("N"), "DataCollectorAttachmentProcessor_1.txt");
Directory.CreateDirectory(Path.GetDirectoryName(tmpAttachment));
File.WriteAllText(tmpAttachment, $"SessionEnded_Handler_{Guid.NewGuid():N}");
_dataCollectionSink.SendFileAsync(_context.SessionDataCollectionContext, tmpAttachment, true);
}
}
}
34 changes: 34 additions & 0 deletions src/Assets/TestProjects/VSTestMultiProjectSolution/sln.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test1", "test1\test1.csproj", "{081584FC-1000-4F74-887E-480E08A2FAD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test2", "test2\test2.csproj", "{F77D1353-8580-46B5-820F-50A899BEA1DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test3", "test3\test3.csproj", "{9D8CCF24-5968-4E57-B181-98A026C8ABEA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{081584FC-1000-4F74-887E-480E08A2FAD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{081584FC-1000-4F74-887E-480E08A2FAD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{081584FC-1000-4F74-887E-480E08A2FAD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{081584FC-1000-4F74-887E-480E08A2FAD4}.Release|Any CPU.Build.0 = Release|Any CPU
{F77D1353-8580-46B5-820F-50A899BEA1DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F77D1353-8580-46B5-820F-50A899BEA1DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F77D1353-8580-46B5-820F-50A899BEA1DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F77D1353-8580-46B5-820F-50A899BEA1DD}.Release|Any CPU.Build.0 = Release|Any CPU
{9D8CCF24-5968-4E57-B181-98A026C8ABEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D8CCF24-5968-4E57-B181-98A026C8ABEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D8CCF24-5968-4E57-B181-98A026C8ABEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D8CCF24-5968-4E57-B181-98A026C8ABEA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace test1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />

<PropertyGroup>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
</ItemGroup>

<ItemGroup>
<!-- Microsoft.NET.Test.Sdk package includes source files which shouldn't be automatically included. -->
<!-- Excluding those -->
<Compile Remove="pkgs\Microsoft.NET.Test.Sdk\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace test2
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />

<PropertyGroup>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
</ItemGroup>

<ItemGroup>
<!-- Microsoft.NET.Test.Sdk package includes source files which shouldn't be automatically included. -->
<!-- Excluding those -->
<Compile Remove="pkgs\Microsoft.NET.Test.Sdk\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace test3
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />

<PropertyGroup>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
</ItemGroup>

<ItemGroup>
<!-- Microsoft.NET.Test.Sdk package includes source files which shouldn't be automatically included. -->
<!-- Excluding those -->
<Compile Remove="pkgs\Microsoft.NET.Test.Sdk\**" />
</ItemGroup>
</Project>
Loading