test: create test for concurrency

This commit is contained in:
voltsrage
2026-06-23 05:17:22 +08:00
parent 383df0dde5
commit d8e142fffe
8 changed files with 2625 additions and 58 deletions
@@ -232,7 +232,20 @@ public class PatientService : IPatientService
CreatedAt = DateTimeOffset.UtcNow
});
await _db.SaveChangesAsync();
try
{
await _db.SaveChangesAsync();
}
catch (DbUpdateException ex)
when (ex.InnerException is Npgsql.PostgresException { SqlState: "23505" } pg
&& pg.ConstraintName == "ix_encounters_patient_active_type")
{
_db.ChangeTracker.Clear();
throw new ConflictException(
"Patient already has an active encounter of this type.",
"DUPLICATE_ACTIVE_ENCOUNTER");
}
return encounter;
}