Fixed flaky longpolling tests (#1993)
- Wait for disposal and removal of the connection
This commit is contained in:
parent
4a568e90d2
commit
83dec1093a
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 _));
|
||||
|
|
|
|||
Loading…
Reference in New Issue