Browse Source

Test that response-start completion rolls back a failed request

pull/26017/head
maliming 15 hours ago
parent
commit
c0d9631016
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 21
      framework/test/Volo.Abp.AspNetCore.Uow.Tests/Volo/Abp/AspNetCore/Uow/UnitOfWorkMiddleware_Relational_Tests.cs
  2. 17
      framework/test/Volo.Abp.AspNetCore.Uow.Tests/Volo/Abp/AspNetCore/Uow/UowVisibilityController.cs

21
framework/test/Volo.Abp.AspNetCore.Uow.Tests/Volo/Abp/AspNetCore/Uow/UnitOfWorkMiddleware_Relational_Tests.cs

@ -117,4 +117,25 @@ public class UnitOfWorkMiddleware_Relational_Tests : AbpWebApplicationFactoryInt
surfaced.ShouldNotBeNull();
(await CountAsync(name)).ShouldBe(0);
}
[Fact]
public async Task Result_Serialization_Failure_Rolls_Back_And_Does_Not_Commit_On_The_Error_Response()
{
EnableCompleteOnResponseStarting();
var name = Guid.NewGuid().ToString("N");
try
{
var response = await Client.GetAsync("/api/uow-visibility/insert-then-throw-in-serialization?name=" + name);
await response.Content.ReadAsStringAsync();
}
catch (Exception)
{
}
// The action saved the row, then serializing the result failed before the response started. The error
// response is written by the upstream exception middleware after the request unit of work is disposed,
// so response-start completion must not commit the failed request.
(await CountAsync(name)).ShouldBe(0);
}
}

17
framework/test/Volo.Abp.AspNetCore.Uow.Tests/Volo/Abp/AspNetCore/Uow/UowVisibilityController.cs

@ -104,4 +104,21 @@ public class UowVisibilityController : AbpController
await Response.WriteAsync("inserted");
await Response.Body.FlushAsync();
}
// The action succeeds (so the action filter saves changes), then serializing the object result throws
// before the response starts. The upstream exception middleware writes the error response after the
// request unit of work is disposed, so response-start completion must not commit the failed request.
[HttpGet]
[Route("insert-then-throw-in-serialization")]
[UnitOfWork(isTransactional: true)]
public async Task<IActionResult> InsertThenThrowInSerialization(string name)
{
await _repository.InsertAsync(new UowVisibilityTestEntity(Guid.NewGuid(), name));
return Ok(new ThrowingOnSerializeDto());
}
public class ThrowingOnSerializeDto
{
public string Value => throw new AbpException("boom while serializing the object result");
}
}

Loading…
Cancel
Save