fix(data): lock racing portfolio publications
This commit is contained in:
@@ -497,9 +497,12 @@ public sealed class PortfolioMigrationPostgresTests(PortfolioMigrationPostgresFi
|
||||
var database = await fixture.CreateMigratedDatabaseAsync();
|
||||
await using var publishConnection = await database.OpenConnectionAsync();
|
||||
await using var rescheduleConnection = await database.OpenConnectionAsync();
|
||||
await using var observerConnection = await database.OpenConnectionAsync();
|
||||
var seed = await SeedCardAsync(publishConnection, isPublic: false);
|
||||
await using var publishTransaction = await publishConnection.BeginTransactionAsync();
|
||||
await using var rescheduleTransaction = await rescheduleConnection.BeginTransactionAsync();
|
||||
var publishPid = await GetBackendPidAsync(publishConnection, publishTransaction);
|
||||
var reschedulePid = await GetBackendPidAsync(rescheduleConnection, rescheduleTransaction);
|
||||
|
||||
await ExecuteNonQueryAsync(
|
||||
publishConnection,
|
||||
@@ -518,14 +521,15 @@ public sealed class PortfolioMigrationPostgresTests(PortfolioMigrationPostgresFi
|
||||
rescheduleTransaction,
|
||||
new NpgsqlParameter("sessionId", seed.SessionIds[0]));
|
||||
|
||||
var commitStates = await Task.WhenAll(
|
||||
CommitAndCaptureSqlStateAsync(publishTransaction),
|
||||
CommitAndCaptureSqlStateAsync(rescheduleTransaction)).WaitAsync(CommandTimeout);
|
||||
var forceRescheduleTriggerTask = ExecuteNonQueryAsync(
|
||||
rescheduleConnection,
|
||||
"SET CONSTRAINTS trg_sessions_unpublish_public_portfolio_games_for_future_reschedule IMMEDIATE",
|
||||
rescheduleTransaction);
|
||||
await WaitUntilBlockedByAsync(observerConnection, reschedulePid, publishPid);
|
||||
|
||||
Assert.True(
|
||||
commitStates[0] is null or PostgresErrorCodes.CheckViolation,
|
||||
$"Unexpected publish SQLSTATE: {commitStates[0] ?? "<none>"}.");
|
||||
Assert.Null(commitStates[1]);
|
||||
Assert.Null(await CommitAndCaptureSqlStateAsync(publishTransaction).WaitAsync(CommandTimeout));
|
||||
await forceRescheduleTriggerTask.WaitAsync(CommandTimeout);
|
||||
await rescheduleTransaction.CommitAsync().WaitAsync(CommandTimeout);
|
||||
|
||||
await using var verificationConnection = await database.OpenConnectionAsync();
|
||||
Assert.False(await ExecuteScalarAsync<bool>(
|
||||
|
||||
Reference in New Issue
Block a user