using Chronos.Data.Copies;
using Chronos.Data.Tests.Infrastructure;
using Chronos.Testing;
namespace Chronos.Data.Tests.Perf;
///
/// Owner review 6 (#73), design ยง3.4: local detection's SHA-256 join over the 500,000-photo library answers in under 2 s
/// (every photo unique: the join finds no pair, which is the whole index read). Opt-in: CHRONOS_PERF=1.
///
[Category("perf")]
[RequiresEnvironment(PerfGate.Variable)]
[Serial]
[Timeout(3_600_000)]
public abstract class CopyOverlapPerfTests(TestContext context) : RepositoryTest(context)
{
public const double BudgetMs = 2_000;
[Test]
public async Task LocalOverlapsAreFoundWithinTheGate()
{
var options = await NewOptionsAsync(multiConnection: true);
await using (var build = await ChronosDatabase.OpenAsync(options, Ct)) await SyntheticLibrary.BuildAsync(build, Context);
var db = Own(await ChronosDatabase.OpenAsync(options, Ct));
var store = new FoundCopyStore(db);
IReadOnlyList overlaps = [];
var first = await PerfGate.TimeAsync(async () => overlaps = await store.LocalOverlapsAsync(Ct));
var again = await PerfGate.MedianAsync(() => store.LocalOverlapsAsync(Ct));
Context.Log($"perf: {Dialect} local overlaps {first:F0} ms first, {again:F0} ms again (budget {BudgetMs:F0} ms), {overlaps.Count} pairs");
Assert.Empty(overlaps);
Assert.LessOrEqual(first, BudgetMs);
}
}
public sealed class SqliteCopyOverlapPerfTests(TestContext context) : CopyOverlapPerfTests(context)
{
protected override Backend Backend => Backend.SqliteFile;
}
[RequiresEnvironment(PgTestServer.Variable)]
public sealed class PostgresCopyOverlapPerfTests(TestContext context) : CopyOverlapPerfTests(context)
{
protected override Backend Backend => Backend.Postgres;
}