diff --git a/src/Anubis/Supervision/SoakReport.cs b/src/Anubis/Supervision/SoakReport.cs index b3e979b..da54803 100644 --- a/src/Anubis/Supervision/SoakReport.cs +++ b/src/Anubis/Supervision/SoakReport.cs @@ -83,8 +83,10 @@ public static class SoakReporter .ConfigureAwait(false); var absences = await s.QueryAsync("SELECT started_at, ended_at FROM absences WHERE ended_at >= @from AND started_at <= @to ORDER BY started_at", r => (Start: r.Moment("started_at"), End: r.Moment("ended_at")), window).ConfigureAwait(false); - var start = jobs.First is { } first && first > from ? first : from; - var end = jobs.Last is { } lastJob && lastJob < to ? lastJob : to; + // A gap shorter than the longest silence allowed at either end (the first jobs come a minute after the start, + // the last one up to 5 minutes before the end) is no more a hole than one in the middle. + var start = jobs.First is { } first && first > from + MaxSilence ? first : from; + var end = jobs.Last is { } lastJob && lastJob < to - MaxSilence ? lastJob : to; var covered = jobs.First is null || jobs.Last is null || end <= start ? TimeSpan.Zero : end - start - absences.Aggregate(TimeSpan.Zero, (sum, a) => sum + (Min(a.End, end) - Max(a.Start, start) is { } span && span > TimeSpan.Zero ? span : TimeSpan.Zero)); checks.Add(new SoakCheck($"Durata coperta dal lavoro del bot: {SoakReport.Hours(covered)} (servono almeno {SoakReport.Hours(minimum)}).", covered >= minimum)); diff --git a/tests/Anubis.Tests/SoakReportTests.cs b/tests/Anubis.Tests/SoakReportTests.cs index 5a534ff..02620a6 100644 --- a/tests/Anubis.Tests/SoakReportTests.cs +++ b/tests/Anubis.Tests/SoakReportTests.cs @@ -54,7 +54,7 @@ public sealed class SoakReportTests var text = report.Markdown(Zones.Rome); Assert.IsTrue(report.Passed, text); Assert.Contains("**Esito: regolare.**", text); - Assert.Contains("Durata coperta dal lavoro del bot: 49,0 ore", text); + Assert.Contains("Durata coperta dal lavoro del bot: 49 ore", text); Assert.Contains("Al lavoro dall'inizio alla fine della finestra.", text); Assert.Contains("Ogni conto riconciliato fino alla fine e in regola: ", text); Assert.Contains("Decisioni di crypto_trend: 2 su 2 chiusure giornaliere.", text);