Prevent background process from crashing test when writing to… (#20254)

This commit is contained in:
John Luo 2020-03-27 16:43:39 -07:00 committed by GitHub
parent da4bd70813
commit e79ba297fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 61 deletions

View File

@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InteropWebsite", "test\test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InteropClient", "test\testassets\InteropClient\InteropClient.csproj", "{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dependencies", "dependencies", "{285E2F1E-E0F9-47ED-BE43-6D84B9A49DA0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Testing", "..\Testing\src\Microsoft.AspNetCore.Testing.csproj", "{3B2B746A-F12E-4E04-9782-6E12F855B50D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -31,6 +35,10 @@ Global
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Release|Any CPU.Build.0 = Release|Any CPU
{3B2B746A-F12E-4E04-9782-6E12F855B50D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B2B746A-F12E-4E04-9782-6E12F855B50D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B2B746A-F12E-4E04-9782-6E12F855B50D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B2B746A-F12E-4E04-9782-6E12F855B50D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -39,6 +47,7 @@ Global
{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2} = {0FFB3605-0203-450F-80C8-F82CA2E8269F}
{3AB7E8E4-BA36-44CE-844E-39DB66E46D45} = {F5841B0A-901A-448F-9CC5-4CB393CE86AF}
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F} = {F5841B0A-901A-448F-9CC5-4CB393CE86AF}
{3B2B746A-F12E-4E04-9782-6E12F855B50D} = {285E2F1E-E0F9-47ED-BE43-6D84B9A49DA0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3CAE66FD-9A59-49C2-B133-1D599225259A}

View File

@ -1,44 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Xunit.Abstractions;
namespace InteropTests.Helpers
{
public class InteropTestsFixture : IDisposable
{
private WebsiteProcess _process;
public string Path { get; set; }
public string ServerPort { get; private set; }
public async Task EnsureStarted(ITestOutputHelper output)
{
if (_process != null)
{
return;
}
if (string.IsNullOrEmpty(Path))
{
throw new InvalidOperationException("Path has not been set.");
}
_process = new WebsiteProcess(Path, output);
await _process.WaitForReady();
ServerPort = _process.ServerPort;
}
public void Dispose()
{
_process.Dispose();
}
}
}

View File

@ -14,22 +14,15 @@ using Xunit.Abstractions;
namespace InteropTests
{
public class InteropTests : IClassFixture<InteropTestsFixture>
public class InteropTests
{
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30);
private readonly string _clientPath = Path.Combine(Directory.GetCurrentDirectory(), "InteropClient", "InteropClient.dll");
private readonly InteropTestsFixture _fixture;
private readonly string _serverPath = Path.Combine(Directory.GetCurrentDirectory(), "InteropWebsite", "InteropWebsite.dll");
private readonly ITestOutputHelper _output;
public InteropTests(InteropTestsFixture fixture, ITestOutputHelper output)
public InteropTests(ITestOutputHelper output)
{
var attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes<AssemblyMetadataAttribute>();
fixture.Path = Path.Combine(Directory.GetCurrentDirectory(), "InteropWebsite", "InteropWebsite.dll");
_fixture = fixture;
_output = output;
}
@ -37,9 +30,11 @@ namespace InteropTests
[MemberData(nameof(TestCaseData))]
public async Task InteropTestCase(string name)
{
await _fixture.EnsureStarted(_output).TimeoutAfter(DefaultTimeout);
using (var serverProcess = new WebsiteProcess(_serverPath, _output))
{
await serverProcess.WaitForReady().TimeoutAfter(DefaultTimeout);
using (var clientProcess = new ClientProcess(_output, _clientPath, _fixture.ServerPort, name))
using (var clientProcess = new ClientProcess(_output, _clientPath, serverProcess.ServerPort, name))
{
await clientProcess.WaitForReady().TimeoutAfter(DefaultTimeout);
@ -48,6 +43,7 @@ namespace InteropTests
Assert.Equal(0, clientProcess.ExitCode);
}
}
}
#region TestData
// All interop test cases, minus GCE authentication specific tests

View File

@ -152,7 +152,7 @@ namespace InteropTestsClient
}
var httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator!;
if (options.UseTestCa ?? false)
{