Files
itworx-knowledge-hub-Public/tests/backend/ItWorx.KnowledgeHub.IntegrationTests/Auth/ConcurrentLoginTests.cs
T

30 lines
1.1 KiB
C#

using System.Net;
using ItWorx.KnowledgeHub.IntegrationTests.Infrastructure;
namespace ItWorx.KnowledgeHub.IntegrationTests.Auth;
/// <summary>Regression coverage for a real bug found via E2E testing: two concurrent
/// logins for the same account raced on ASP.NET Core Identity's optimistic-concurrency
/// token while recording the last-login timestamp, turning a successful authentication
/// into a 500 for whichever request lost the race.</summary>
[Collection(PostgresTestGroup.Name)]
public sealed class ConcurrentLoginTests(PostgresContainerFixture postgres) : OwnerSetupTestBase(postgres)
{
[Fact]
public async Task Concurrent_logins_for_the_same_account_never_fail_with_a_server_error()
{
using var clientA = Factory.CreateClient();
using var clientB = Factory.CreateClient();
var loginA = SetupHelper.LoginAsync(clientA, OwnerEmail, OwnerPassword);
var loginB = SetupHelper.LoginAsync(clientB, OwnerEmail, OwnerPassword);
var results = await Task.WhenAll(loginA, loginB);
foreach (var response in results)
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
}