Ensure KestrelThreads get stopped in tests if there is a startup failure
This commit is contained in:
parent
b55bef20aa
commit
850632a091
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue