Files
Chronos/tests/Titano.Data.Tests/Repositories/BulkInsertTests.cs
T
Claude 2fbb7bc179 test(data): cover migrations and every repository on both dialects
Shared abstract suites run against in-memory/temp-file SQLite and, with
TITANO_TEST_PG, a private PostgreSQL schema per test: migration
idempotency and version refusal, keyset paging with ties for every sort,
statistics, exclusive job claiming under 8 concurrent claimers, and the
100k-frame bulk insert under 15 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 10:05:43 +00:00

43 lines
1.7 KiB
C#

using System.Diagnostics;
using Titano.Data.Tests.Infrastructure;
using Titano.Testing;
namespace Titano.Data.Tests.Repositories;
/// <summary>The 100k-frame import of the Phase 2 gate must stay well under 15 s.</summary>
public abstract class BulkInsertTests(TestContext context) : RepositoryTest(context)
{
[Test]
[Timeout(60_000)]
public async Task HundredThousandFramesInsertQuickly()
{
var db = await OpenTitanoAsync(multiConnection: true);
var archive = TestData.Archive();
await db.Archives.UpsertAsync(archive, Ct);
var sequence = TestData.Sequence(archive.Id);
await db.Sequences.UpsertAsync(sequence, Ct);
var frames = Enumerable.Range(0, 100_000).Select(i => TestData.Frame(sequence.Id, i)).ToList();
var watch = Stopwatch.StartNew();
Assert.Equal(100_000L, await db.Frames.BulkInsertAsync(frames, Ct));
watch.Stop();
Context.Log($"{Dialect}: 100k frames in {watch.Elapsed.TotalSeconds:F2} s");
Assert.Less(watch.Elapsed.TotalSeconds, 15.0, "bulk insert time");
var refreshed = await db.Sequences.RefreshStatsAsync(sequence.Id, Ct);
Assert.Equal(100_000, refreshed!.FrameCount);
Assert.Equal(frames[^1], (await db.Frames.ListBySequenceAsync(sequence.Id, afterIndex: 99_998, cancellationToken: Ct)).Single());
}
}
public sealed class SqliteBulkInsertTests(TestContext context) : BulkInsertTests(context)
{
protected override Backend Backend => Backend.SqliteFile;
}
[RequiresEnvironment(PgTestServer.Variable)]
public sealed class PostgresBulkInsertTests(TestContext context) : BulkInsertTests(context)
{
protected override Backend Backend => Backend.Postgres;
}