Add wait in ListenerPrimaryTests to avoid race condition with List.Add

This commit is contained in:
Nate McMaster 2017-04-25 15:53:30 -07:00
parent d9dad9400c
commit 9464003bda
2 changed files with 17 additions and 0 deletions

View File

@ -33,6 +33,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
}
/// <summary>
/// For testing purposes.
/// </summary>
public int UvPipeCount => _dispatchPipes.Count;
private UvPipeHandle ListenPipe { get; set; }
public async Task StartAsync(

View File

@ -53,12 +53,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address));
Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address));
var listenerCount = listenerPrimary.UvPipeCount;
// Add secondary listener
var libuvThreadSecondary = new LibuvThread(libuvTransport);
await libuvThreadSecondary.StartAsync();
var listenerSecondary = new ListenerSecondary(transportContextSecondary);
await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary);
var maxWait = Task.Delay(TimeSpan.FromSeconds(30));
// wait for ListenerPrimary.ReadCallback to add the secondary pipe
while (listenerPrimary.UvPipeCount == listenerCount)
{
var completed = await Task.WhenAny(maxWait, Task.Delay(100));
if (ReferenceEquals(completed, maxWait))
{
throw new TimeoutException("Timed out waiting for secondary listener to become available");
}
}
// Once a secondary listener is added, TCP connections start getting dispatched to it
await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" });