-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle correctly waiting for process exit on Unix systems (#3410)
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
- Loading branch information
1 parent
dec0aa8
commit f77ec07
Showing
6 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
49 changes: 49 additions & 0 deletions
49
test/Microsoft.TestPlatform.AcceptanceTests/ProcessesInteractionTests.cs
This file contains 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,49 @@ | ||
// 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.IO; | ||
|
||
using Microsoft.TestPlatform.TestUtilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.TestPlatform.AcceptanceTests; | ||
|
||
[TestClass] | ||
public class ProcessesInteractionTests : AcceptanceTestBase | ||
{ | ||
/// <summary> | ||
/// Having an invalid framework is a way to reproduce an issue we had on Unix, where we were | ||
/// not handling correctly the process exit (causing us to not let time to the process to | ||
/// flush its output and error streams).See https://github.com/microsoft/vstest/issues/3375 | ||
/// </summary> | ||
[TestMethod] | ||
[NetCoreTargetFrameworkDataSource] | ||
public void WhenTestHostProcessExitsBecauseTheTargetedRuntimeIsNoFoundThenTheMessageIsCapturedFromTheErrorOutput(RunnerInfo runnerInfo) | ||
{ | ||
// Arrange | ||
SetTestEnvironment(_testEnvironment, runnerInfo); | ||
const string testAssetProjectName = "SimpleTestProjectMessedUpTargetFramework"; | ||
var assemblyPath = GetAssetFullPath(testAssetProjectName + ".dll", Core21TargetFramework); | ||
UpdateRuntimeConfigJsonWithInvalidFramework(assemblyPath, testAssetProjectName); | ||
using var tempDir = new TempDirectory(); | ||
|
||
// Act | ||
var arguments = PrepareArguments(assemblyPath, GetTestAdapterPath(), "", FrameworkArgValue, tempDir.Path); | ||
InvokeVsTest(assemblyPath); | ||
|
||
// Assert | ||
ExitCodeEquals(1); | ||
StdErrorContains("The framework 'Microsoft.NETCore.App', version '0.0.0' (x64) was not found."); | ||
|
||
static void UpdateRuntimeConfigJsonWithInvalidFramework(string assemblyPath, string testAssetProjectName) | ||
{ | ||
// On the contrary to other tests, we need to modify the test asset we are using to replace | ||
// the target framework with an invalid framework. This is why we have a specific test asset | ||
// that's only meant to be used by this project. | ||
var runtimeConfigJson = Path.Combine(Path.GetDirectoryName(assemblyPath), testAssetProjectName + ".runtimeconfig.json"); | ||
var fileContent = File.ReadAllText(runtimeConfigJson); | ||
var updatedContent = fileContent.Replace("\"version\": \"2.1.0\"", "\"version\": \"0.0.0\""); | ||
File.WriteAllText(runtimeConfigJson, updatedContent); | ||
} | ||
} | ||
} |
This file contains 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
25 changes: 25 additions & 0 deletions
25
.../SimpleTestProjectMessedUpTargetFramework/SimpleTestProjectMessedUpTargetFramework.csproj
This file contains 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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<!-- Imports Common TestAssets props. --> | ||
<Import Project="..\..\..\scripts\build\TestAssets.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks> | ||
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">netcoreapp3.1</TargetFrameworks> | ||
<TestProject>true</TestProject> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MSTest.TestFramework"> | ||
<Version>$(MSTestFrameworkVersion)</Version> | ||
</PackageReference> | ||
<PackageReference Include="MSTest.TestAdapter"> | ||
<Version>$(MSTestAdapterVersion)</Version> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk"> | ||
<Version>$(NETTestSdkVersion)</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
16 changes: 16 additions & 0 deletions
16
test/TestAssets/SimpleTestProjectMessedUpTargetFramework/UnitTest1.cs
This file contains 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,16 @@ | ||
// 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.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace SimpleTestProjectMessedUpTargetFramework | ||
{ | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
} | ||
} | ||
} |
This file contains 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