Skip to content

Commit bc95b12

Browse files
committed
Better BuildServerTestFixtureBase dispose timeouts
1 parent 277cc56 commit bc95b12

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerIntegrationTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -225,7 +225,7 @@ public async Task Build_WithWhiteSpaceInPipeName_BuildsSuccessfully()
225225
finally
226226
{
227227
// Shutdown the server
228-
fixture.Dispose();
228+
await fixture.DisposeAsync();
229229
}
230230
}
231231

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
1111
/// Note that this fixture will always initialize a server of the current version since it
1212
/// invokes the ServerConnection API from the referenced rzc.
1313
/// </summary>
14-
public class BuildServerTestFixture : BuildServerTestFixtureBase, IDisposable
14+
public class BuildServerTestFixture : BuildServerTestFixtureBase
1515
{
1616
public BuildServerTestFixture() : this(Guid.NewGuid().ToString())
1717
{

src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildServerTestFixtureBase.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Runtime.InteropServices;
88
using System.Threading;
9+
using System.Threading.Tasks;
910
using Microsoft.AspNetCore.Razor.Tools;
1011
using Microsoft.CodeAnalysis;
1112
using Moq;
13+
using Xunit;
1214

1315
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
1416
{
15-
public abstract class BuildServerTestFixtureBase : IDisposable
17+
public abstract class BuildServerTestFixtureBase : IAsyncLifetime
1618
{
1719
private static readonly TimeSpan _defaultShutdownTimeout = TimeSpan.FromSeconds(120);
1820

@@ -23,19 +25,18 @@ protected BuildServerTestFixtureBase(string pipeName)
2325

2426
public string PipeName { get; }
2527

26-
public void Dispose()
28+
public Task InitializeAsync()
29+
{
30+
return Task.CompletedTask;
31+
}
32+
33+
public async Task DisposeAsync()
2734
{
2835
// Shutdown the build server.
2936
using (var cts = new CancellationTokenSource(_defaultShutdownTimeout))
3037
{
3138
var writer = new StringWriter();
3239

33-
cts.Token.Register(() =>
34-
{
35-
var output = writer.ToString();
36-
throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.{Environment.NewLine}Output: {output}.");
37-
});
38-
3940
var application = new Application(cts.Token, Mock.Of<ExtensionAssemblyLoader>(), Mock.Of<ExtensionDependencyChecker>(), (path, properties) => Mock.Of<PortableExecutableReference>(), writer, writer);
4041

4142
var args = new List<string>
@@ -52,7 +53,21 @@ public void Dispose()
5253
args.Add("-w");
5354
}
5455

55-
var exitCode = application.Execute(args.ToArray());
56+
var executeTask = Task.Run(() => application.Execute(args.ToArray()));
57+
58+
if (executeTask == await Task.WhenAny(executeTask, Task.Delay(Timeout.Infinite, cts.Token)))
59+
{
60+
// Complete the Task.Delay
61+
cts.Cancel();
62+
}
63+
else
64+
{
65+
var output = writer.ToString();
66+
throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.{Environment.NewLine}Output: {output}.");
67+
}
68+
69+
var exitCode = await executeTask;
70+
5671
if (exitCode != 0)
5772
{
5873
var output = writer.ToString();

src/Shared/CertificateGeneration/CertificateManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ public void TrustCertificateStart(string certificate)
942942
}
943943

944944
[Event(30, Level = EventLevel.Verbose)]
945-
public void TrustCertificateEnd() =>WriteEvent(30, "Finished trusting the certificate.");
945+
public void TrustCertificateEnd() => WriteEvent(30, "Finished trusting the certificate.");
946946

947947
[Event(31, Level = EventLevel.Error)]
948948
public void TrustCertificateError(string ex)

0 commit comments

Comments
 (0)