Files
Chronos/tests/Chronos.Data.Tests/Repositories/BulkInsertTests.cs
T
Alby96andClaude Opus 5.5 8566072c9a
CI / Build and test (pull_request) Successful in 8m3s
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 14s
CI / PostgreSQL 16 integration (pull_request) Successful in 5m56s
CI / PostgreSQL 17 integration (pull_request) Successful in 6m5s
CI / Docker image (pull_request) Successful in 1m18s
test: stretch timed budgets on the shared CI runner
The owner's runner shares its CPU and disks with Gitea and the server's other
containers, so the 100k-frame bulk insert took 10-19 s against 15 s from one
run to the next. CHRONOS_TEST_TIME_FACTOR (default 1) stretches the timed
tests' budgets; CI and release set 3, the weekly performance gates keep them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:19:36 +02:00

43 lines
1.7 KiB
C#

using System.Diagnostics;
using Chronos.Data.Tests.Infrastructure;
using Chronos.Testing;
namespace Chronos.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 OpenChronosAsync(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, TestTiming.Budget(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;
}