Add wait in ListenerPrimaryTests to avoid race condition with List.Add
This commit is contained in:
parent
d9dad9400c
commit
9464003bda
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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" });
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue