提交 7f93acea 编写于 作者: J Jared Parsons

Don't look at timeout value

Under stress scenarios even seeing if the timeout was at least a
specific period of time fails.  Going to a simpler check that we simply
hit the value.
上级 af2aea32
......@@ -26,6 +26,11 @@ internal interface IDiagnosticListener
/// result.
/// </summary>
void DetectedBadConnection();
/// <summary>
/// Called when the server is shutting down because the keep alive timeout was reached.
/// </summary>
void KeepAliveReached();
}
internal sealed class EmptyDiagnosticListener : IDiagnosticListener
......@@ -41,5 +46,9 @@ public void ConnectionProcessed(int count)
public void DetectedBadConnection()
{
}
public void KeepAliveReached()
{
}
}
}
......@@ -95,6 +95,7 @@ public void ListenAndDispatchConnections(TimeSpan? keepAlive, CancellationToken
if ((timeoutTask != null && timeoutTask.IsCompleted) || cancellationToken.IsCancellationRequested)
{
_diagnosticListener.KeepAliveReached();
listenCancellationTokenSource.Cancel();
break;
}
......
......@@ -22,6 +22,7 @@ private sealed class TestableDiagnosticListener : IDiagnosticListener
public DateTime? LastProcessedTime;
public TimeSpan? KeepAlive;
public bool HasDetectedBadConnection;
public bool HitKeepAliveTimeout;
public void ConnectionProcessed(int count)
{
......@@ -38,6 +39,11 @@ public void DetectedBadConnection()
{
HasDetectedBadConnection = true;
}
public void KeepAliveReached()
{
HitKeepAliveTimeout = true;
}
}
private static readonly BuildRequest s_emptyCSharpBuildRequest = new BuildRequest(
......@@ -185,11 +191,12 @@ public void KeepAliveNoConnections()
.Setup(x => x.CreateListenTask(It.IsAny<CancellationToken>()))
.Returns(new TaskCompletionSource<IClientConnection>().Task);
var dispatcher = new ServerDispatcher(connectionHost.Object, new EmptyDiagnosticListener());
var listener = new TestableDiagnosticListener();
var dispatcher = new ServerDispatcher(connectionHost.Object, listener);
var startTime = DateTime.Now;
dispatcher.ListenAndDispatchConnections(keepAlive);
Assert.True((DateTime.Now - startTime) > keepAlive);
Assert.True(listener.HitKeepAliveTimeout);
}
/// <summary>
......@@ -209,7 +216,7 @@ public void KeepAliveAfterSingleConnection()
Assert.Equal(1, listener.ProcessedCount);
Assert.True(listener.LastProcessedTime.HasValue);
Assert.True((DateTime.Now - listener.LastProcessedTime.Value) > keepAlive);
Assert.True(listener.HitKeepAliveTimeout);
}
/// <summary>
......@@ -235,7 +242,7 @@ public void KeepAliveAfterMultipleConnection()
Assert.Equal(count, listener.ProcessedCount);
Assert.True(listener.LastProcessedTime.HasValue);
Assert.True((DateTime.Now - listener.LastProcessedTime.Value) > keepAlive);
Assert.True(listener.HitKeepAliveTimeout);
}
/// <summary>
......@@ -282,7 +289,7 @@ public async Task KeepAliveAfterSimultaneousConnection()
await dispatcherTask.ConfigureAwait(true);
Assert.Equal(totalCount, listener.ProcessedCount);
Assert.True(listener.LastProcessedTime.HasValue);
Assert.True((DateTime.Now - listener.LastProcessedTime.Value) > keepAlive);
Assert.True(listener.HitKeepAliveTimeout);
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册