diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerIntegrationTest.cs index 005ac4ccf6b4..2a094e78e256 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerIntegrationTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -225,7 +225,7 @@ public async Task Build_WithWhiteSpaceInPipeName_BuildsSuccessfully() finally { // Shutdown the server - fixture.Dispose(); + await fixture.DisposeAsync(); } } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixture.cs b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixture.cs index 52c242cc318c..6bd919958287 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixture.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixture.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests /// Note that this fixture will always initialize a server of the current version since it /// invokes the ServerConnection API from the referenced rzc. /// - public class BuildServerTestFixture : BuildServerTestFixtureBase, IDisposable + public class BuildServerTestFixture : BuildServerTestFixtureBase { public BuildServerTestFixture() : this(Guid.NewGuid().ToString()) { diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixtureBase.cs b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixtureBase.cs index 69440c6bee81..208439dafb14 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixtureBase.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixtureBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -6,13 +6,15 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Tools; using Microsoft.CodeAnalysis; using Moq; +using Xunit; namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { - public abstract class BuildServerTestFixtureBase : IDisposable + public abstract class BuildServerTestFixtureBase : IAsyncLifetime { private static readonly TimeSpan _defaultShutdownTimeout = TimeSpan.FromSeconds(120); @@ -23,19 +25,18 @@ protected BuildServerTestFixtureBase(string pipeName) public string PipeName { get; } - public void Dispose() + public Task InitializeAsync() + { + return Task.CompletedTask; + } + + public async Task DisposeAsync() { // Shutdown the build server. using (var cts = new CancellationTokenSource(_defaultShutdownTimeout)) { var writer = new StringWriter(); - cts.Token.Register(() => - { - var output = writer.ToString(); - throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.{Environment.NewLine}Output: {output}."); - }); - var application = new Application(cts.Token, Mock.Of(), Mock.Of(), (path, properties) => Mock.Of(), writer, writer); var args = new List @@ -52,7 +53,21 @@ public void Dispose() args.Add("-w"); } - var exitCode = application.Execute(args.ToArray()); + var executeTask = Task.Run(() => application.Execute(args.ToArray())); + + if (executeTask == await Task.WhenAny(executeTask, Task.Delay(Timeout.Infinite, cts.Token))) + { + // Complete the Task.Delay + cts.Cancel(); + } + else + { + var output = writer.ToString(); + throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.{Environment.NewLine}Output: {output}."); + } + + var exitCode = await executeTask; + if (exitCode != 0) { var output = writer.ToString(); diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index 5e5f19e93870..b0c1870d0f62 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -942,7 +942,7 @@ public void TrustCertificateStart(string certificate) } [Event(30, Level = EventLevel.Verbose)] - public void TrustCertificateEnd() =>WriteEvent(30, "Finished trusting the certificate."); + public void TrustCertificateEnd() => WriteEvent(30, "Finished trusting the certificate."); [Event(31, Level = EventLevel.Error)] public void TrustCertificateError(string ex)