Fixed flaky longpolling tests (#1993)

- Wait for disposal and removal of the connection
This commit is contained in:
David Fowler 2018-04-13 00:42:31 -07:00 committed by GitHub
parent 4a568e90d2
commit 83dec1093a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -79,6 +79,9 @@ namespace Microsoft.AspNetCore.Http.Connections
public SemaphoreSlim Lock { get; } = new SemaphoreSlim(1, 1);
// Used for testing only
internal Task DisposeAndRemoveTask { get; set; }
public Task TransportTask { get; set; }
public Task ApplicationTask { get; set; }

View File

@ -516,8 +516,9 @@ namespace Microsoft.AspNetCore.Http.Connections
// Complete the receiving end of the pipe
connection.Application.Output.Complete();
// Dispose the connection gracefully, but don't wait for it
_ = _manager.DisposeAndRemoveAsync(connection, closeGracefully: true);
// Dispose the connection gracefully, but don't wait for it. We assign it here so we can wait in tests
connection.DisposeAndRemoveTask = _manager.DisposeAndRemoveAsync(connection, closeGracefully: true);
context.Response.StatusCode = StatusCodes.Status202Accepted;
context.Response.ContentType = "text/plain";
}

View File

@ -1709,13 +1709,17 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
await dispatcher.ExecuteAsync(deleteContext, options, app).OrTimeout();
// Verify the response from the DELETE request
Assert.Equal(StatusCodes.Status202Accepted, deleteContext.Response.StatusCode);
Assert.Equal("text/plain", deleteContext.Response.ContentType);
// Verify that everything shuts down
await connection.ApplicationTask.OrTimeout();
await connection.TransportTask.OrTimeout();
// Verify the response from the DELETE request
Assert.Equal(StatusCodes.Status202Accepted, deleteContext.Response.StatusCode);
Assert.Equal("text/plain", deleteContext.Response.ContentType);
Assert.NotNull(connection.DisposeAndRemoveTask);
await connection.DisposeAndRemoveTask.OrTimeout();
// Verify the connection was removed from the manager
Assert.False(manager.TryGetConnection(connection.ConnectionId, out _));