-
Notifications
You must be signed in to change notification settings - Fork 352
Add post processing intergration test #3377
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
Merged
nohwnd
merged 1 commit into
microsoft:main
from
MarcoRossignoli:postprocessingintegration
Feb 16, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
test/Microsoft.TestPlatform.AcceptanceTests/PostProcessingTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.TestPlatform.AcceptanceTests; | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using System.Xml; | ||
| using System.Xml.Linq; | ||
|
|
||
| using Microsoft.TestPlatform.TestUtilities; | ||
| using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
| using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| [TestClass] | ||
| public class PostProcessingTests : AcceptanceTestBase | ||
| { | ||
| [TestMethod] | ||
| public void DotnetSDKSimulation_PostProcessing() | ||
| { | ||
| using var tempDir = new TempDirectory(); | ||
|
|
||
| var extensionsPath = Path.Combine( | ||
| _testEnvironment.TestAssetsPath, | ||
| Path.GetFileNameWithoutExtension("AttachmentProcessorDataCollector"), | ||
| "bin", | ||
| IntegrationTestEnvironment.BuildConfiguration, | ||
| "netstandard2.0"); | ||
| _testEnvironment.RunnerFramework = CoreRunnerFramework; | ||
|
|
||
| string runSettings = GetRunsettingsFilePath(tempDir.Path); | ||
| string correlationSessionId = Guid.NewGuid().ToString(); | ||
|
|
||
| // Set datacollector parameters | ||
| XElement runSettingsXml = XElement.Load(runSettings); | ||
| runSettingsXml.Element("DataCollectionRunSettings") | ||
| .Element("DataCollectors") | ||
| .Element("DataCollector") | ||
| .Add(new XElement("Configuration", new XElement("MergeFile", "MergedFile.txt"))); | ||
| runSettingsXml.Save(runSettings); | ||
|
|
||
| // Build and run tests like msbuild | ||
| Parallel.For(0, 5, i => | ||
| { | ||
| string projectFolder = Path.Combine(tempDir.Path, i.ToString()); | ||
| ExecuteApplication(GetConsoleRunnerPath(), $"new mstest -o {projectFolder}", out string stdOut, out string stdError, out int exitCode); | ||
| Assert.AreEqual(exitCode, 0); | ||
| ExecuteApplication(GetConsoleRunnerPath(), $"build {projectFolder} -c release", out stdOut, out stdError, out exitCode); | ||
| Assert.AreEqual(exitCode, 0); | ||
|
|
||
| string testContainer = Directory.GetFiles(Path.Combine(projectFolder, "bin"), $"{i}.dll", SearchOption.AllDirectories).Single(); | ||
|
|
||
| ExecuteVsTestConsole($"{testContainer} --Collect:\"SampleDataCollector\" --TestAdapterPath:\"{extensionsPath}\" --ResultsDirectory:\"{Path.GetDirectoryName(testContainer)}\" --Settings:\"{runSettings}\" --ArtifactsProcessingMode-Collect --TestSessionCorrelationId:\"{correlationSessionId}\" --Diag:\"{tempDir.Path + '/'}\"", out stdOut, out stdError, out exitCode, | ||
| new Dictionary<string, string>() { { "VSTEST_FEATURE_ARTIFACTS_POSTPROCESSING", "1" } }); | ||
| Assert.AreEqual(exitCode, 0); | ||
| }); | ||
|
|
||
| // Post process artifacts | ||
| ExecuteVsTestConsole($"--ArtifactsProcessingMode-PostProcess --TestSessionCorrelationId:\"{correlationSessionId}\" --Diag:\"{tempDir.Path + '/'}\"", out string stdOut, out string stdError, out int exitCode, | ||
| new Dictionary<string, string>() { { "VSTEST_FEATURE_ARTIFACTS_POSTPROCESSING", "1" } }); | ||
| Assert.AreEqual(exitCode, 0); | ||
|
|
||
| using StringReader reader = new(stdOut); | ||
| Assert.AreEqual(string.Empty, reader.ReadLine().Trim()); | ||
| Assert.AreEqual("Attachments:", reader.ReadLine().Trim()); | ||
| string mergedFile = reader.ReadLine().Trim(); | ||
| Assert.AreEqual(string.Empty, reader.ReadLine().Trim()); | ||
| Assert.IsNull(reader.ReadLine()); | ||
|
|
||
| var fileContent = new List<string>(); | ||
| using var streamReader = new StreamReader(mergedFile); | ||
| while (!streamReader.EndOfStream) | ||
| { | ||
| string line = streamReader.ReadLine(); | ||
| Assert.IsTrue(line.StartsWith("SessionEnded_Handler_")); | ||
| fileContent.Add(line); | ||
| } | ||
|
|
||
| Assert.AreEqual(5, fileContent.Distinct().Count()); | ||
| } | ||
|
|
||
| private static string GetRunsettingsFilePath(string resultsDir) | ||
| { | ||
| var runsettingsPath = Path.Combine(resultsDir, "test_" + Guid.NewGuid() + ".runsettings"); | ||
| var dataCollectionAttributes = new Dictionary<string, string> | ||
| { | ||
| { "friendlyName", "SampleDataCollector" }, | ||
| { "uri", "my://sample/datacollector" } | ||
| }; | ||
|
|
||
| CreateDataCollectionRunSettingsFile(runsettingsPath, dataCollectionAttributes); | ||
| return runsettingsPath; | ||
| } | ||
|
|
||
| private static void CreateDataCollectionRunSettingsFile(string destinationRunsettingsPath, Dictionary<string, string> dataCollectionAttributes) | ||
| { | ||
| var doc = new XmlDocument(); | ||
| var xmlDeclaration = doc.CreateNode(XmlNodeType.XmlDeclaration, string.Empty, string.Empty); | ||
|
|
||
| doc.AppendChild(xmlDeclaration); | ||
| var runSettingsNode = doc.CreateElement(Constants.RunSettingsName); | ||
| doc.AppendChild(runSettingsNode); | ||
| var dcConfigNode = doc.CreateElement(Constants.DataCollectionRunSettingsName); | ||
| runSettingsNode.AppendChild(dcConfigNode); | ||
| var dataCollectorsNode = doc.CreateElement(Constants.DataCollectorsSettingName); | ||
| dcConfigNode.AppendChild(dataCollectorsNode); | ||
| var dataCollectorNode = doc.CreateElement(Constants.DataCollectorSettingName); | ||
| dataCollectorsNode.AppendChild(dataCollectorNode); | ||
|
|
||
| foreach (var kvp in dataCollectionAttributes) | ||
| { | ||
| dataCollectorNode.SetAttribute(kvp.Key, kvp.Value); | ||
| } | ||
|
|
||
| using var stream = new FileHelper().GetStream(destinationRunsettingsPath, FileMode.Create); | ||
| doc.Save(stream); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.