fix: issue #29 — integration tests flakiness (DB split + SqlTestFixture consolidado) #34

Merged
dmolinari merged 7 commits from fix/issue-29-flakiness into main 2026-04-19 10:41:27 +00:00
2 changed files with 17 additions and 4 deletions
Showing only changes of commit e987228f14 - Show all commits

View File

@@ -16,7 +16,14 @@ public sealed class SqlTestFixture : IAsyncLifetime
private SqlConnection _connection = null!; private SqlConnection _connection = null!;
private Respawner _respawner = null!; private Respawner _respawner = null!;
public SqlTestFixture(string connectionString) /// <summary>Parameterless ctor for xUnit ICollectionFixture — uses SIGCM2_Test_App.</summary>
public SqlTestFixture() : this(TestConnectionStrings.AppTestDb) { }
/// <summary>
/// Explicit connection string ctor — used by TestWebAppFactory (same assembly).
/// Internal to satisfy xUnit's "single public constructor" rule for ICollectionFixture.
/// </summary>
internal SqlTestFixture(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
@@ -80,6 +87,13 @@ public sealed class SqlTestFixture : IAsyncLifetime
await ResetAndSeedAsync(); await ResetAndSeedAsync();
} }
/// <summary>
/// Exposes the open SqlConnection for tests that need to run ad-hoc queries
/// (e.g. seed extra rows, assert history tables). Connection is opened during
/// InitializeAsync and closed in DisposeAsync.
/// </summary>
public SqlConnection Connection => _connection;
public async Task ResetAndSeedAsync() public async Task ResetAndSeedAsync()
{ {
await _respawner.ResetAsync(_connection); await _respawner.ResetAsync(_connection);

View File

@@ -13,12 +13,11 @@ namespace SIGCM2.TestSupport;
/// <summary> /// <summary>
/// WebApplicationFactory for integration tests against SIGCM2.Api. /// WebApplicationFactory for integration tests against SIGCM2.Api.
/// Uses SIGCM2_Test database (separate from production SIGCM2). /// Uses SIGCM2_Test_Api database (isolated from Application.Tests which uses SIGCM2_Test_App).
/// </summary> /// </summary>
public sealed class TestWebAppFactory : WebApplicationFactory<Program>, IAsyncLifetime public sealed class TestWebAppFactory : WebApplicationFactory<Program>, IAsyncLifetime
{ {
private const string TestConnectionString = private const string TestConnectionString = TestConnectionStrings.ApiTestDb;
"Server=TECNICA3;Database=SIGCM2_Test;User Id=desarrollo;Password=desarrollo2026;TrustServerCertificate=True;";
// Resolved once — absolute paths independent of working directory // Resolved once — absolute paths independent of working directory
private static readonly string RepoRoot = ResolveRepoRoot(); private static readonly string RepoRoot = ResolveRepoRoot();