From e79ba297fda9597cee8888d8fe9ea2b906df7a21 Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 27 Mar 2020 16:43:39 -0700 Subject: [PATCH] =?UTF-8?q?Prevent=20background=20process=20from=20crashin?= =?UTF-8?q?g=20test=20when=20writing=20to=E2=80=A6=20(#20254)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Grpc/Grpc.sln | 9 ++++ .../Helpers/InteropTestsFixture.cs | 44 ------------------- src/Grpc/test/InteropTests/InteropTests.cs | 28 +++++------- .../testassets/InteropClient/InteropClient.cs | 2 +- 4 files changed, 22 insertions(+), 61 deletions(-) delete mode 100644 src/Grpc/test/InteropTests/Helpers/InteropTestsFixture.cs diff --git a/src/Grpc/Grpc.sln b/src/Grpc/Grpc.sln index d1491ed3e3..971b92e9a5 100644 --- a/src/Grpc/Grpc.sln +++ b/src/Grpc/Grpc.sln @@ -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} diff --git a/src/Grpc/test/InteropTests/Helpers/InteropTestsFixture.cs b/src/Grpc/test/InteropTests/Helpers/InteropTestsFixture.cs deleted file mode 100644 index 86ffff4a07..0000000000 --- a/src/Grpc/test/InteropTests/Helpers/InteropTestsFixture.cs +++ /dev/null @@ -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(); - } - } -} diff --git a/src/Grpc/test/InteropTests/InteropTests.cs b/src/Grpc/test/InteropTests/InteropTests.cs index b12ec316dc..42b4bafe8a 100644 --- a/src/Grpc/test/InteropTests/InteropTests.cs +++ b/src/Grpc/test/InteropTests/InteropTests.cs @@ -14,22 +14,15 @@ using Xunit.Abstractions; namespace InteropTests { - public class InteropTests : IClassFixture + 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(); - - fixture.Path = Path.Combine(Directory.GetCurrentDirectory(), "InteropWebsite", "InteropWebsite.dll"); - - _fixture = fixture; _output = output; } @@ -37,15 +30,18 @@ namespace InteropTests [MemberData(nameof(TestCaseData))] public async Task InteropTestCase(string name) { - await _fixture.EnsureStarted(_output).TimeoutAfter(DefaultTimeout); - - using (var clientProcess = new ClientProcess(_output, _clientPath, _fixture.ServerPort, name)) + using (var serverProcess = new WebsiteProcess(_serverPath, _output)) { - await clientProcess.WaitForReady().TimeoutAfter(DefaultTimeout); + await serverProcess.WaitForReady().TimeoutAfter(DefaultTimeout); - await clientProcess.Exited.TimeoutAfter(DefaultTimeout); + using (var clientProcess = new ClientProcess(_output, _clientPath, serverProcess.ServerPort, name)) + { + await clientProcess.WaitForReady().TimeoutAfter(DefaultTimeout); - Assert.Equal(0, clientProcess.ExitCode); + await clientProcess.Exited.TimeoutAfter(DefaultTimeout); + + Assert.Equal(0, clientProcess.ExitCode); + } } } diff --git a/src/Grpc/test/testassets/InteropClient/InteropClient.cs b/src/Grpc/test/testassets/InteropClient/InteropClient.cs index 27d51f6998..63ad341a35 100644 --- a/src/Grpc/test/testassets/InteropClient/InteropClient.cs +++ b/src/Grpc/test/testassets/InteropClient/InteropClient.cs @@ -152,7 +152,7 @@ namespace InteropTestsClient } var httpClientHandler = new HttpClientHandler(); - httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; + httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator!; if (options.UseTestCa ?? false) {