提交 9e4be409 编写于 作者: J Jared Parsons

Merge pull request #11514 from jaredpar/fix

Fix a flaky compiler suite
......@@ -41,7 +41,7 @@ protected override IClientConnectionHost CreateClientConnectionHost(string pipeN
return connectionHost;
}
protected override TimeSpan? GetKeepAliveTimeout()
protected internal override TimeSpan? GetKeepAliveTimeout()
{
return null;
}
......
......@@ -37,7 +37,7 @@ internal int Run(string[] args)
: RunServer(pipeName, cancellationToken: cancellationTokenSource.Token);
}
protected abstract TimeSpan? GetKeepAliveTimeout();
protected internal abstract TimeSpan? GetKeepAliveTimeout();
protected abstract string GetDefaultPipeName();
......
......@@ -14,11 +14,21 @@
using System.Globalization;
using Microsoft.CodeAnalysis.CommandLine;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
namespace Microsoft.CodeAnalysis.CompilerServer
{
internal class DesktopBuildServerController : BuildServerController
{
internal const string KeepAliveSettingName = "keepalive";
private readonly NameValueCollection _appSettings;
internal DesktopBuildServerController(NameValueCollection appSettings = null)
{
_appSettings = appSettings ?? ConfigurationManager.AppSettings;
}
protected override IClientConnectionHost CreateClientConnectionHost(string pipeName)
{
// VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
......@@ -29,12 +39,12 @@ protected override IClientConnectionHost CreateClientConnectionHost(string pipeN
return new NamedPipeClientConnectionHost(compilerServerHost, pipeName);
}
protected override TimeSpan? GetKeepAliveTimeout()
protected internal override TimeSpan? GetKeepAliveTimeout()
{
try
{
int keepAliveValue;
string keepAliveStr = ConfigurationManager.AppSettings["keepalive"];
string keepAliveStr = _appSettings[KeepAliveSettingName];
if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) &&
keepAliveValue >= 0)
{
......
......@@ -1300,31 +1300,6 @@ public async Task Utf8OutputInRspFileVbc()
}
}
[Fact, WorkItem(1095079, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095079")]
public async Task ServerRespectsAppConfig()
{
var exeConfigPath = Path.Combine(CompilerDirectory, CompilerServerExeName + ".config");
var doc = new XmlDocument();
using (XmlReader reader = XmlReader.Create(exeConfigPath, new XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }))
{
doc.Load(reader);
}
var root = doc.DocumentElement;
root.SelectSingleNode("appSettings/add/@value").Value = "1";
doc.Save(exeConfigPath);
var proc = StartProcess(CompilerServerExecutable, "");
await Task.Delay(TimeSpan.FromSeconds(3)).ConfigureAwait(false); // Give 2s leeway
var exited = proc.HasExited;
if (!exited)
{
Kill(proc);
Assert.True(false, "Compiler server did not exit in time");
}
}
[Fact]
public void BadKeepAlive1()
{
......
// Copyright (c) Microsoft. 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.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.CodeAnalysis.CompilerServer.UnitTests
{
public class DesktopBuildServerControllerTests
{
public sealed class GetKeepAliveTimeoutTests
{
private readonly NameValueCollection _appSettings = new NameValueCollection();
private readonly DesktopBuildServerController _controller;
public GetKeepAliveTimeoutTests()
{
_controller = new DesktopBuildServerController(_appSettings);
}
[Fact]
public void Simple()
{
_appSettings[DesktopBuildServerController.KeepAliveSettingName] = "42";
Assert.Equal(TimeSpan.FromSeconds(42), _controller.GetKeepAliveTimeout());
}
[Fact]
public void InvalidNumber()
{
_appSettings[DesktopBuildServerController.KeepAliveSettingName] = "dog";
Assert.Equal(ServerDispatcher.DefaultServerKeepAlive, _controller.GetKeepAliveTimeout());
}
[Fact]
public void NoSetting()
{
Assert.Equal(ServerDispatcher.DefaultServerKeepAlive, _controller.GetKeepAliveTimeout());
}
}
}
}
......@@ -120,6 +120,7 @@
<Compile Include="CompilerServerApiTest.cs" />
<Compile Include="CompilerServerTests.cs" />
<Compile Include="DesktopBuildClientTests.cs" />
<Compile Include="DesktopBuildServerControllerTests.cs" />
<Compile Include="EndToEndDeterminismTest.cs" />
<Compile Include="VBCSCompilerServerTests.cs" />
<Compile Include="MockEngine.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册