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);
|
public SemaphoreSlim Lock { get; } = new SemaphoreSlim(1, 1);
|
||||||
|
|
||||||
|
// Used for testing only
|
||||||
|
internal Task DisposeAndRemoveTask { get; set; }
|
||||||
|
|
||||||
public Task TransportTask { get; set; }
|
public Task TransportTask { get; set; }
|
||||||
|
|
||||||
public Task ApplicationTask { get; set; }
|
public Task ApplicationTask { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -516,8 +516,9 @@ namespace Microsoft.AspNetCore.Http.Connections
|
||||||
// Complete the receiving end of the pipe
|
// Complete the receiving end of the pipe
|
||||||
connection.Application.Output.Complete();
|
connection.Application.Output.Complete();
|
||||||
|
|
||||||
// Dispose the connection gracefully, but don't wait for it
|
// Dispose the connection gracefully, but don't wait for it. We assign it here so we can wait in tests
|
||||||
_ = _manager.DisposeAndRemoveAsync(connection, closeGracefully: true);
|
connection.DisposeAndRemoveTask = _manager.DisposeAndRemoveAsync(connection, closeGracefully: true);
|
||||||
|
|
||||||
context.Response.StatusCode = StatusCodes.Status202Accepted;
|
context.Response.StatusCode = StatusCodes.Status202Accepted;
|
||||||
context.Response.ContentType = "text/plain";
|
context.Response.ContentType = "text/plain";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1709,13 +1709,17 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
|
|
||||||
await dispatcher.ExecuteAsync(deleteContext, options, app).OrTimeout();
|
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
|
// Verify that everything shuts down
|
||||||
await connection.ApplicationTask.OrTimeout();
|
await connection.ApplicationTask.OrTimeout();
|
||||||
await connection.TransportTask.OrTimeout();
|
await connection.TransportTask.OrTimeout();
|
||||||
|
|
||||||
// Verify the response from the DELETE request
|
Assert.NotNull(connection.DisposeAndRemoveTask);
|
||||||
Assert.Equal(StatusCodes.Status202Accepted, deleteContext.Response.StatusCode);
|
|
||||||
Assert.Equal("text/plain", deleteContext.Response.ContentType);
|
await connection.DisposeAndRemoveTask.OrTimeout();
|
||||||
|
|
||||||
// Verify the connection was removed from the manager
|
// Verify the connection was removed from the manager
|
||||||
Assert.False(manager.TryGetConnection(connection.ConnectionId, out _));
|
Assert.False(manager.TryGetConnection(connection.ConnectionId, out _));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue