Ensure KestrelThreads get stopped in tests if there is a startup failure

This commit is contained in:
Stephen Halter 2016-03-04 15:22:52 -08:00
parent b55bef20aa
commit 850632a091
1 changed files with 14 additions and 9 deletions

View File

@ -33,20 +33,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public int Port => _address.Port;
public TestServer(RequestDelegate app, ServiceContext context, string serverAddress)
{
Create(app, context, serverAddress);
}
public void Create(RequestDelegate app, ServiceContext context, string serverAddress)
{
context.FrameFactory = connectionContext =>
{
return new Frame<HttpContext>(new DummyApplication(app), connectionContext);
};
_engine = new KestrelEngine(context);
_engine.Start(1);
_address = ServerAddress.FromUrl(serverAddress);
_server = _engine.CreateServer(_address);
try
{
_engine = new KestrelEngine(context);
_engine.Start(1);
_address = ServerAddress.FromUrl(serverAddress);
_server = _engine.CreateServer(_address);
}
catch
{
_server?.Dispose();
_engine?.Dispose();
throw;
}
}
public void Dispose()