Misura delle prestazioni dell'interfaccia con 60 aste (#34)
I criteri della specifica §9.11 (frame, blocchi del thread, riga aggiornata entro 100 ms, riconnessione sotto i 2 s, nessun ridisegno della griglia con maniglie e finestra) non li misurava nessuno. Ora il simulatore prende --simulatore-aste N (solo con --simulatore): N aste in elenco, tre su quattro in Attiva, ciclo di 5 s e due autopuntate senza fine per asta, così almeno dieci aste stanno sempre sotto i 4 s; senza l'argomento il simulatore resta quello di sempre. tools/Mimante.Schermate ha la modalità --misura <secondi>, tutta via CDP: uno script nella pagina cronometra frame, compiti dell'interfaccia (timer, frame, eventi del puntatore, ResizeObserver) e messaggi del bot, chiude il canale per la riconnessione, trascina la maniglia e ridimensiona la finestra controllando che i <tr data-id> restino gli stessi nodi, che la griglia non scorra né si virtualizzi e che anche lì nessun compito blocchi il thread; scrive misura.json e misura.txt ed esce con 1 se un criterio vincolante fallisce (anche un solo compito lungo del browser) o la misura non vale (basta un campione con meno di dieci aste in finestra critica; la CPU si riporta soltanto). La password può venire da UI_PASSWORD. prove-a-mano.yml ha il lavoro «prestazioni», dopo carico e schermate per non dividere la CPU, e il commento sul mondo del simulatore è corretto. Le prove dei conti della misura stanno in tests/Mimante.Tests con un riferimento a tools/Mimante.Schermate che esiste solo se la cartella c'è: il contesto dell'immagine non ha tools/ e lì quelle prove restano fuori, così la costruzione dell'immagine non si rompe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ea6ba27462
commit
d84d396f86
19 files changed
+1812
-43
No files matched your search
@@ -16,6 +16,22 @@
|
||||
<ProjectReference Include="..\..\src\Mimante\Mimante.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
I conti della misura delle prestazioni (Misura/PerfAnalysis) e gli argomenti dello strumento delle schermate.
|
||||
tools/ non entra nel contesto dell'immagine (.dockerignore; docker/Dockerfile copia solo src/ e tests/): lì il
|
||||
riferimento manca e PerfAnalysisTests resta fuori dalla compilazione. Quelle prove girano nel lavoro «prove» di
|
||||
verifica.yml e rilascio.yml, che hanno tutto il repository (PipelineTests.TheImageBuildsTheTestsWithoutTools).
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<SchermateProject>..\..\tools\Mimante.Schermate\Mimante.Schermate.csproj</SchermateProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="Exists('$(SchermateProject)')">
|
||||
<ProjectReference Include="$(SchermateProject)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="!Exists('$(SchermateProject)')">
|
||||
<Compile Remove="PerfAnalysisTests.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Risposte registrate dal sito vero: i parser si provano su quelle. -->
|
||||
<None Include="Fixtures\**\*" CopyToOutputDirectory="PreserveNewest" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Mimante.Tests.Packaging;
|
||||
@@ -119,6 +120,15 @@ public sealed partial class PipelineTests
|
||||
Assert.Contains("--simulatore", Job(workflow, "schermate"));
|
||||
Assert.DoesNotContain("--simulatore", Code(Job(workflow, "carico")));
|
||||
|
||||
// The performance trial (#34) runs alone after the others, with 60 simulated auctions, and gets the password of
|
||||
// the interface from UI_PASSWORD, never on its command line.
|
||||
var performance = Code(Job(workflow, "prestazioni"));
|
||||
Assert.Contains("needs: [carico, schermate]", performance);
|
||||
Assert.Contains("--simulatore --simulatore-aste 60", performance);
|
||||
Assert.Contains("Mimante.Schermate.dll http://localhost:8080 out/prestazioni --misura 120", performance);
|
||||
Assert.DoesNotContain("$UI_PASSWORD", performance);
|
||||
Assert.Contains("uses: actions/upload-artifact@v3", performance);
|
||||
|
||||
var load = Code(Script("prova-carico.sh"));
|
||||
Assert.Contains("docker network create --internal", load);
|
||||
Assert.Contains("--memory=1g", load);
|
||||
@@ -166,6 +176,43 @@ public sealed partial class PipelineTests
|
||||
Assert.StartsWith("#!/usr/bin/env bash", File.ReadAllText(file));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The build stage of docker/Dockerfile compiles tests/Mimante.Tests with only src/ and tests/ in the context
|
||||
/// (.dockerignore drops tools/): a reference of the test project outside those two folders must depend on the
|
||||
/// project being there, and the tests that need it must leave the compilation when it is not (issue #34).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TheImageBuildsTheTestsWithoutTools()
|
||||
{
|
||||
var ignore = Read(".dockerignore").Split('\n').Select(l => l.Trim()).ToList();
|
||||
Assert.Contains("tools", ignore);
|
||||
var dockerfile = Read("docker", "Dockerfile");
|
||||
Assert.DoesNotContain("COPY tools", dockerfile);
|
||||
|
||||
var project = XDocument.Parse(Read("tests", "Mimante.Tests", "Mimante.Tests.csproj"));
|
||||
var properties = project.Descendants("PropertyGroup").Elements()
|
||||
.ToDictionary(e => e.Name.LocalName, e => e.Value, StringComparer.OrdinalIgnoreCase);
|
||||
string Expand(string value) =>
|
||||
Regex.Replace(value, @"\$\((?<p>[A-Za-z0-9_]+)\)", m => properties.GetValueOrDefault(m.Groups["p"].Value, m.Value));
|
||||
|
||||
foreach (var reference in project.Descendants("ProjectReference"))
|
||||
{
|
||||
var path = Expand((string?)reference.Attribute("Include") ?? "").Replace('\\', '/');
|
||||
var inContext = !path.StartsWith("../../", StringComparison.Ordinal)
|
||||
|| path.StartsWith("../../src/", StringComparison.Ordinal) || path.StartsWith("../../tests/", StringComparison.Ordinal);
|
||||
if (inContext) continue;
|
||||
var condition = Expand((string?)reference.Parent?.Attribute("Condition") ?? "").Replace('\\', '/');
|
||||
Assert.True(condition.Contains($"Exists('{path}')", StringComparison.Ordinal), $"{path}: reference without Exists(...)");
|
||||
var removed = project.Descendants("Compile")
|
||||
.Where(c => Expand((string?)c.Parent?.Attribute("Condition") ?? "").Replace('\\', '/') == $"!Exists('{path}')")
|
||||
.Select(c => (string?)c.Attribute("Remove"))
|
||||
.ToList();
|
||||
Assert.NotEmpty(removed);
|
||||
}
|
||||
Assert.Contains("Exists('../../tools/Mimante.Schermate/Mimante.Schermate.csproj')",
|
||||
Expand(Read("tests", "Mimante.Tests", "Mimante.Tests.csproj")).Replace('\\', '/'));
|
||||
}
|
||||
|
||||
// ---- helpers ----
|
||||
|
||||
private static string Workflow(string name) => Read(".gitea", "workflows", name);
|
||||
|
||||
@@ -0,0 +1,352 @@
|
||||
using Mimante.Schermate;
|
||||
using Mimante.Schermate.Misura;
|
||||
using Xunit;
|
||||
|
||||
namespace Mimante.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// I conti della misura delle prestazioni dell'interfaccia (tools/Mimante.Schermate --misura, specifica §9.11,
|
||||
/// issue #34): frame, distribuzioni, righe ridisegnate, giudizio e argomenti dello strumento.
|
||||
/// </summary>
|
||||
public class PerfAnalysisTests
|
||||
{
|
||||
private static List<double> Steady(int count, double frame = 16.67) => Enumerable.Repeat(frame, count).ToList();
|
||||
|
||||
[Fact]
|
||||
public void Frame_regolari_non_perdono_nulla()
|
||||
{
|
||||
var f = PerfAnalysis.Frames(Steady(600));
|
||||
Assert.Equal(600, f.Intervals);
|
||||
Assert.Equal(16.67, f.FrameMs);
|
||||
Assert.Equal(0, f.LostFrames);
|
||||
Assert.Equal(0, f.Blocks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Un_intervallo_lungo_conta_i_frame_che_mancano_e_il_blocco()
|
||||
{
|
||||
var intervals = Steady(300);
|
||||
intervals.Add(50); // due frame saltati, il thread fermo 33 ms
|
||||
intervals.Add(24); // sotto 1,5 frame: ritardo, non frame perso
|
||||
var f = PerfAnalysis.Frames(intervals);
|
||||
Assert.Equal(2, f.LostFrames);
|
||||
Assert.Equal(1, f.Blocks);
|
||||
Assert.Equal(33.33, f.WorstBlockMs, 2);
|
||||
Assert.Equal(50, f.WorstGapMs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void La_durata_del_frame_segue_lo_schermo()
|
||||
{
|
||||
// A 30 Hz un intervallo di 33 ms è normale.
|
||||
var f = PerfAnalysis.Frames(Steady(200, 33.3));
|
||||
Assert.Equal(33.3, f.FrameMs);
|
||||
Assert.Equal(0, f.LostFrames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Senza_frame_niente_conti()
|
||||
{
|
||||
var f = PerfAnalysis.Frames([]);
|
||||
Assert.Equal(0, f.Intervals);
|
||||
Assert.Equal(0, f.LostFrames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Percentili_al_rango_piu_vicino()
|
||||
{
|
||||
var values = Enumerable.Range(1, 100).Select(i => (double)i).ToList();
|
||||
var d = PerfAnalysis.Distribution(values, 95);
|
||||
Assert.Equal(100, d.Count);
|
||||
Assert.Equal(50, d.P50);
|
||||
Assert.Equal(95, d.P95);
|
||||
Assert.Equal(99, d.P99);
|
||||
Assert.Equal(100, d.Max);
|
||||
Assert.Equal(5, d.Over);
|
||||
Assert.Equal(0, PerfAnalysis.Distribution([], 100).Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Una_riga_ancora_in_vista_con_un_nodo_nuovo_e_ridisegnata()
|
||||
{
|
||||
var before = new List<(string, long)> { ("1", 1), ("2", 2), ("3", 3) };
|
||||
var after = new List<(string, long)> { ("1", 1), ("2", 9), ("3", 3) };
|
||||
var r = PerfAnalysis.CompareRows(before, after);
|
||||
Assert.False(r.Intact);
|
||||
Assert.Equal(new[] { "2" }, r.Replaced);
|
||||
Assert.Equal(2, r.Kept);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Riordino_e_scorrimento_virtuale_non_sono_errori()
|
||||
{
|
||||
// Lo stesso nodo spostato (insertBefore) tiene il suo segno; una riga uscita di vista e una entrata non contano.
|
||||
var before = new List<(string, long)> { ("1", 1), ("2", 2), ("3", 3) };
|
||||
var after = new List<(string, long)> { ("3", 3), ("1", 1), ("4", 4) };
|
||||
var r = PerfAnalysis.CompareRows(before, after);
|
||||
Assert.True(r.Intact);
|
||||
Assert.Equal(2, r.Kept);
|
||||
Assert.Equal(3, r.Before);
|
||||
Assert.Equal(3, r.After);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Una_riga_doppia_e_un_errore()
|
||||
{
|
||||
var r = PerfAnalysis.CompareRows([("1", 1)], [("1", 1), ("1", 5)]);
|
||||
Assert.False(r.Intact);
|
||||
Assert.Equal(new[] { "1" }, r.Duplicated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Una_misura_buona_supera_tutti_i_criteri_vincolanti()
|
||||
{
|
||||
var report = PerfAnalysis.Evaluate(Good(), "http://localhost:8080", DateTimeOffset.UnixEpoch);
|
||||
Assert.True(report.Valid, string.Join("; ", report.InvalidReasons));
|
||||
Assert.True(report.Passed);
|
||||
Assert.Equal(0, report.ExitCode);
|
||||
Assert.Contains("SUPERATA", PerfAnalysis.Text(report));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void La_CPU_alta_si_riporta_ma_non_fa_fallire()
|
||||
{
|
||||
var report = PerfAnalysis.Evaluate(Good() with { CpuPercent = 60 }, "x", DateTimeOffset.UnixEpoch);
|
||||
var cpu = Assert.Single(report.Checks, c => c.Key == "cpu");
|
||||
Assert.False(cpu.Binding);
|
||||
Assert.False(cpu.Passed);
|
||||
Assert.True(report.Passed);
|
||||
Assert.Contains("non vincolante", PerfAnalysis.Text(report));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("frames")]
|
||||
[InlineData("blocks")]
|
||||
[InlineData("row_update")]
|
||||
[InlineData("reconnect")]
|
||||
[InlineData("drag")]
|
||||
[InlineData("resize")]
|
||||
[InlineData("js_errors")]
|
||||
public void Un_criterio_vincolante_fallito_esce_con_uno(string key)
|
||||
{
|
||||
var input = Good();
|
||||
input = key switch
|
||||
{
|
||||
"frames" => input with { FrameIntervals = [.. input.FrameIntervals, 70] },
|
||||
"blocks" => input with { TasksMs = [.. input.TasksMs, 22] },
|
||||
"row_update" => input with { RowUpdatesMs = [.. input.RowUpdatesMs, 140] },
|
||||
"reconnect" => input with { ReconnectsMs = [400, null, 380] },
|
||||
"drag" => input with { Drag = input.Drag with { Rows = PerfAnalysis.CompareRows([("1", 1)], [("1", 2)]) } },
|
||||
"resize" => input with { Resize = input.Resize with { Rows = PerfAnalysis.CompareRows([("1", 1), ("2", 2)], [("1", 1), ("2", 7)]) } },
|
||||
_ => input with { Errors = ["eccezione: TypeError"] }
|
||||
};
|
||||
var report = PerfAnalysis.Evaluate(input, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.True(report.Valid);
|
||||
Assert.False(Assert.Single(report.Checks, c => c.Key == key).Passed);
|
||||
Assert.Equal(1, report.ExitCode);
|
||||
Assert.Contains("NON SUPERATA", PerfAnalysis.Text(report));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Un_frame_saltato_senza_compiti_lunghi_non_e_un_blocco_del_thread()
|
||||
{
|
||||
var input = Good();
|
||||
var report = PerfAnalysis.Evaluate(input with { FrameIntervals = [.. input.FrameIntervals, 33.4] }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(Assert.Single(report.Checks, c => c.Key == "frames").Passed);
|
||||
Assert.True(Assert.Single(report.Checks, c => c.Key == "blocks").Passed);
|
||||
|
||||
var browser = PerfAnalysis.Evaluate(input with { LongTasksMs = [64] }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(Assert.Single(browser.Checks, c => c.Key == "blocks").Passed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Con_meno_di_dieci_aste_in_finestra_critica_la_misura_non_vale()
|
||||
{
|
||||
var samples = Enumerable.Range(0, 120).Select(i => new PerfSample(60, 45, i % 2 == 0 ? 12 : 7, 60, true)).ToList();
|
||||
var report = PerfAnalysis.Evaluate(Good() with { Samples = samples }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(report.Valid);
|
||||
Assert.Contains(report.InvalidReasons, r => r.Contains("sotto i 4 s"));
|
||||
Assert.Equal(1, report.ExitCode);
|
||||
Assert.Contains("NON VALIDA", PerfAnalysis.Text(report));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basta_un_campione_con_meno_di_dieci_aste_in_finestra_critica()
|
||||
{
|
||||
// Nessuna tolleranza: 119 campioni buoni e uno con 9 aste sotto i 4 s non bastano (richiesta della issue #34).
|
||||
var samples = Enumerable.Range(0, 120).Select(i => new PerfSample(60, 45, i == 77 ? 9 : 22, 60, true)).ToList();
|
||||
var report = PerfAnalysis.Evaluate(Good() with { Samples = samples }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(report.Valid);
|
||||
Assert.Contains(report.InvalidReasons, r => r.Contains("solo 9 aste"));
|
||||
|
||||
var exactly = Enumerable.Range(0, 120).Select(_ => new PerfSample(60, 45, 10, 60, true)).ToList();
|
||||
Assert.True(PerfAnalysis.Evaluate(Good() with { Samples = exactly }, "x", DateTimeOffset.UnixEpoch).Valid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Una_griglia_che_scorre_durante_la_maniglia_rende_la_misura_non_valida()
|
||||
{
|
||||
var input = Good();
|
||||
var grid = PerfAnalysis.Grid([(0, 60, false), (0, 60, false), (38, 60, false), (0, 60, false)]);
|
||||
Assert.Equal(38, grid.ScrollMovedPx);
|
||||
var report = PerfAnalysis.Evaluate(input with { Drag = input.Drag with { Grid = grid } }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(report.Valid);
|
||||
Assert.Contains(report.InvalidReasons, r => r.Contains("scorsa di 38 px"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, true)]
|
||||
public void Una_griglia_virtualizzata_o_troppo_lunga_rende_la_misura_non_valida(bool virtualized, bool inResize)
|
||||
{
|
||||
var input = Good();
|
||||
var grid = PerfAnalysis.Grid([(0, 60, false), (0, virtualized ? 30 : 61, virtualized)]);
|
||||
var report = PerfAnalysis.Evaluate(inResize ? input with { Resize = input.Resize with { Grid = grid } } : input with { Drag = input.Drag with { Grid = grid } },
|
||||
"x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(report.Valid);
|
||||
Assert.Contains(report.InvalidReasons, r => r.Contains(inResize ? "ridimensionamento" : "maniglia") && r.Contains(virtualized ? "virtualizzata" : "61 righe"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void La_griglia_si_misura_dal_punto_di_partenza()
|
||||
{
|
||||
Assert.Equal(new GridState(0, 0, false), PerfAnalysis.Grid([]));
|
||||
var g = PerfAnalysis.Grid([(120, 58, false), (118, 60, false), (125.5, 59, false)]);
|
||||
Assert.Equal(5.5, g.ScrollMovedPx);
|
||||
Assert.Equal(60, g.MaxDrawn);
|
||||
Assert.False(g.Virtual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, false)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, true)]
|
||||
public void I_blocchi_di_maniglia_e_finestra_fanno_fallire(bool inResize, bool longTask)
|
||||
{
|
||||
var input = Good();
|
||||
GesturePhase Slow(GesturePhase p) => longTask
|
||||
? p with { LongTasksMs = [72] }
|
||||
: p with { Tasks = PerfAnalysis.Tasks([0.4, 0.5], [3, 21]) };
|
||||
var changed = inResize ? input with { Resize = Slow(input.Resize) } : input with { Drag = Slow(input.Drag) };
|
||||
var report = PerfAnalysis.Evaluate(changed, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.True(report.Valid, string.Join("; ", report.InvalidReasons));
|
||||
Assert.False(Assert.Single(report.Checks, c => c.Key == "blocks").Passed);
|
||||
Assert.Equal(1, report.ExitCode);
|
||||
Assert.Contains(inResize ? "finestra: griglia" : "maniglia: pannello", PerfAnalysis.Text(report));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Con_meno_di_sessanta_aste_in_elenco_la_misura_non_vale()
|
||||
{
|
||||
var samples = Enumerable.Range(0, 120).Select(_ => new PerfSample(14, 3, 12, 14, true)).ToList();
|
||||
var report = PerfAnalysis.Evaluate(Good() with { Samples = samples }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(report.Valid);
|
||||
Assert.Contains(report.InvalidReasons, r => r.Contains("--simulatore-aste 60"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Una_maniglia_che_non_si_muove_rende_la_misura_non_valida()
|
||||
{
|
||||
var input = Good();
|
||||
var report = PerfAnalysis.Evaluate(input with { Drag = input.Drag with { MovedPx = 0 } }, "x", DateTimeOffset.UnixEpoch);
|
||||
Assert.False(report.Valid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void La_CPU_e_il_tempo_dei_compiti_sul_tempo_trascorso()
|
||||
{
|
||||
Assert.Equal(12.5, PerfRun.Cpu((10, 100), (12.5, 120)));
|
||||
Assert.Null(PerfRun.Cpu(null, (1, 2)));
|
||||
Assert.Null(PerfRun.Cpu((1, 5), (2, 5)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lo_script_della_pagina_ha_le_soglie_dentro()
|
||||
{
|
||||
var js = PerfScript.Build();
|
||||
Assert.DoesNotContain("__CRITICAL_MS__", js);
|
||||
Assert.Contains("ms < 4000", js);
|
||||
Assert.Contains("window.WebSocket = PerfSocket", js);
|
||||
Assert.Contains("nativeRaf(loop)", js);
|
||||
Assert.Contains("window.requestAnimationFrame = fn =>", js);
|
||||
Assert.Contains("EventTarget.prototype.removeEventListener", js);
|
||||
Assert.Contains("window.ResizeObserver = class", js);
|
||||
Assert.Contains("grid()", js);
|
||||
}
|
||||
|
||||
// ── Argomenti ───────────────────────────────────────────────────────
|
||||
|
||||
private static Arguments Parse(string? envPassword, params string[] args) =>
|
||||
Arguments.Parse(args, k => k == "UI_PASSWORD" ? envPassword : null, out _);
|
||||
|
||||
[Fact]
|
||||
public void Le_schermate_di_sempre_hanno_tre_argomenti()
|
||||
{
|
||||
var a = Arguments.Parse(["http://localhost:8080/", "dev", "docs/schermate", "--messaggio"], _ => null, out var error);
|
||||
Assert.Null(error);
|
||||
Assert.Equal("http://localhost:8080", a.BaseUrl);
|
||||
Assert.Equal("dev", a.Password);
|
||||
Assert.Equal("docs/schermate", a.OutputDir);
|
||||
Assert.True(a.Message);
|
||||
Assert.Null(a.MeasureSeconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Senza_password_fra_gli_argomenti_vale_UI_PASSWORD()
|
||||
{
|
||||
var a = Parse("dall-ambiente", "http://localhost:8080", "out/misura", "--misura", "120");
|
||||
Assert.Equal("dall-ambiente", a.Password);
|
||||
Assert.Equal("out/misura", a.OutputDir);
|
||||
Assert.Equal(120, a.MeasureSeconds);
|
||||
|
||||
Arguments.Parse(["http://localhost:8080", "out"], _ => null, out var error);
|
||||
Assert.Contains("UI_PASSWORD", error);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("5")]
|
||||
[InlineData("4000")]
|
||||
[InlineData("due")]
|
||||
public void La_durata_della_misura_va_da_dieci_secondi_a_un_ora(string value)
|
||||
{
|
||||
Arguments.Parse(["http://localhost:8080", "dev", "out", "--misura", value], _ => null, out var error);
|
||||
Assert.Contains("--misura", error);
|
||||
Arguments.Parse(["http://localhost:8080", "dev", "out", "--misura"], _ => null, out var missing);
|
||||
Assert.Contains("--misura", missing);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Mockup_e_aiuto()
|
||||
{
|
||||
Assert.True(Parse(null, "--help").Help);
|
||||
var m = Parse(null, "--mockup");
|
||||
Assert.True(m.Mockup);
|
||||
Assert.Equal("docs/mockup/redesign", m.OutputDir);
|
||||
Assert.Equal("altrove", Parse(null, "--mockup", "altrove").OutputDir);
|
||||
Assert.Contains("--misura", Arguments.Usage);
|
||||
}
|
||||
|
||||
private static PerfInputs Good()
|
||||
{
|
||||
var rows = new List<(string, long)> { ("1", 1), ("2", 2), ("3", 3) };
|
||||
var gesture = new GesturePhase(PerfAnalysis.CompareRows(rows, rows), PerfAnalysis.Frames(Steady(60)),
|
||||
PerfAnalysis.Tasks([0.3, 0.4], [1.2, 2.5, 0.8]), [], 0, PerfAnalysis.Grid([(0, 60, false), (0, 60, false)]));
|
||||
return new PerfInputs
|
||||
{
|
||||
Seconds = 120,
|
||||
Samples = Enumerable.Range(0, 120).Select(_ => new PerfSample(60, 45, 22, 60, true)).ToList(),
|
||||
FrameIntervals = Steady(7200),
|
||||
RowUpdatesMs = Enumerable.Range(0, 5000).Select(i => 5.0 + i % 20).ToList(),
|
||||
HandlersMs = Enumerable.Range(0, 5000).Select(i => 0.2 + i % 3 * 0.1).ToList(),
|
||||
TasksMs = Enumerable.Range(0, 2400).Select(i => 0.5 + i % 7 * 0.3).ToList(),
|
||||
LongTasksMs = [],
|
||||
CpuPercent = 8,
|
||||
Drag = gesture with { MovedPx = 240 },
|
||||
Resize = gesture,
|
||||
ReconnectsMs = [450, 470, 430],
|
||||
Errors = []
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using Mimante.Config;
|
||||
using Mimante.Engine;
|
||||
using Mimante.Host;
|
||||
using Mimante.Simulator;
|
||||
using Xunit;
|
||||
|
||||
namespace Mimante.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// <c>--simulatore-aste N</c>: il simulatore a N aste per la misura delle prestazioni dell'interfaccia
|
||||
/// (specifica §9.11, issue #34). Senza l'argomento il simulatore resta quello di sempre.
|
||||
/// </summary>
|
||||
public class SimulatorPlanTests
|
||||
{
|
||||
private static EnvConfig Read(params string[] args) => EnvConfig.Read(_ => null, args);
|
||||
|
||||
[Fact]
|
||||
public void L_argomento_vale_solo_con_il_simulatore()
|
||||
{
|
||||
Assert.Equal(60, Read("--simulatore", "--simulatore-aste", "60").SimulatorAuctions);
|
||||
Assert.Equal(60, Read("--simulatore-aste", "60", "--simulatore").SimulatorAuctions);
|
||||
Assert.Null(Read("--simulatore-aste", "60").SimulatorAuctions);
|
||||
Assert.False(Read("--simulatore-aste", "60").SimulatorMode);
|
||||
Assert.Null(Read("--simulatore").SimulatorAuctions);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("-3")]
|
||||
[InlineData("501")]
|
||||
[InlineData("sessanta")]
|
||||
[InlineData("")]
|
||||
public void Un_numero_non_valido_lascia_il_simulatore_di_sempre(string value)
|
||||
{
|
||||
var env = Read("--simulatore", "--simulatore-aste", value);
|
||||
Assert.True(env.SimulatorMode);
|
||||
Assert.Null(env.SimulatorAuctions);
|
||||
Assert.Same(SimulatorPlan.Default, SimulatorPlan.From(env.SimulatorAuctions));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void L_argomento_in_fondo_senza_numero_non_rompe_la_lettura()
|
||||
{
|
||||
var env = Read("--simulatore", "--simulatore-aste");
|
||||
Assert.True(env.SimulatorMode);
|
||||
Assert.Null(env.SimulatorAuctions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Senza_argomento_il_simulatore_resta_quello_di_sempre()
|
||||
{
|
||||
var plan = SimulatorPlan.From(null);
|
||||
Assert.Equal(14, plan.WorldAuctions);
|
||||
Assert.Equal(8, plan.SeedAuctions);
|
||||
Assert.Equal(6, plan.RunningAuctions);
|
||||
Assert.Null(plan.FreqSeconds);
|
||||
Assert.False(plan.Load);
|
||||
// Tre in Attiva, l'ottava in Ferma, le altre in Osserva; il rabbocco una su tre in Attiva.
|
||||
Assert.Equal(new[] { RunMode.Active, RunMode.Active, RunMode.Active, RunMode.Watch, RunMode.Watch, RunMode.Watch, RunMode.Watch, RunMode.Stopped },
|
||||
Enumerable.Range(0, 8).Select(plan.SeedMode));
|
||||
Assert.Equal(new[] { RunMode.Active, RunMode.Watch, RunMode.Watch, RunMode.Active, RunMode.Watch, RunMode.Watch },
|
||||
Enumerable.Range(0, 6).Select(plan.TopUpMode));
|
||||
|
||||
// Il mondo di sempre: 14 aste, ciascuna con la frequenza del suo prodotto.
|
||||
var world = new SimWorld(seed: 5);
|
||||
Assert.Equal(14, world.Auctions.Count);
|
||||
Assert.Null(world.FixedFreqSeconds);
|
||||
Assert.False(world.EndlessAuctions);
|
||||
Assert.Contains(world.Auctions, a => a.FreqSeconds == 15);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Con_sessanta_aste_il_mondo_ha_margine_e_quasi_tutte_puntano()
|
||||
{
|
||||
var plan = SimulatorPlan.ForLoad(60);
|
||||
Assert.True(plan.Load);
|
||||
Assert.Equal(60, plan.SeedAuctions);
|
||||
Assert.Equal(60, plan.RunningAuctions);
|
||||
Assert.Equal(SimulatorPlan.LoadFreqSeconds, plan.FreqSeconds);
|
||||
Assert.True(plan.WorldAuctions >= 60 + 10, $"mondo di {plan.WorldAuctions} aste");
|
||||
|
||||
var seed = Enumerable.Range(0, plan.SeedAuctions).Select(plan.SeedMode).ToList();
|
||||
Assert.Equal(45, seed.Count(m => m == RunMode.Active));
|
||||
Assert.DoesNotContain(RunMode.Stopped, seed);
|
||||
Assert.Equal(RunMode.Active, plan.TopUpMode(0));
|
||||
|
||||
// Il mondo ha abbastanza aste aperte (programmate comprese) per il seme.
|
||||
var world = NewWorld(plan, seed: 9, out _);
|
||||
Assert.Equal(plan.WorldAuctions, world.Auctions.Count);
|
||||
Assert.True(world.Auctions.Count(a => a.Status == "ON") >= plan.SeedAuctions);
|
||||
Assert.All(world.Auctions, a => Assert.Equal(5, a.FreqSeconds));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Poche_aste_chiedono_comunque_il_mondo_minimo()
|
||||
{
|
||||
var plan = SimulatorPlan.ForLoad(3);
|
||||
Assert.Equal(14, plan.WorldAuctions);
|
||||
Assert.Equal(3, plan.SeedAuctions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Un_asta_di_prova_tiene_la_sua_frequenza_anche_con_il_ciclo_fisso()
|
||||
{
|
||||
var world = new SimWorld(seed: 1, populate: false) { FixedFreqSeconds = 5 };
|
||||
Assert.Equal(12, world.AddRunningAuction(seconds: 8, freq: 12).FreqSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// La ragione del ciclo di 5 s e delle aste che non chiudono: con le sole puntate degli avversari (il bot ne
|
||||
/// aggiunge altre), fra le aste che il seme mette in Attiva ce ne sono sempre almeno dieci insieme sotto i 4 s,
|
||||
/// e in due minuti di prova nessuna chiude.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Con_il_ciclo_di_cinque_secondi_dieci_aste_in_Attiva_stanno_insieme_sotto_i_quattro_secondi()
|
||||
{
|
||||
var plan = SimulatorPlan.ForLoad(60);
|
||||
var world = NewWorld(plan, seed: 17, out var clock);
|
||||
var seeded = world.Auctions.Where(a => a.Status == "ON").Take(plan.SeedAuctions).ToList();
|
||||
var active = seeded.Where((_, i) => plan.SeedMode(i) == RunMode.Active).Select(a => a.Id).ToHashSet();
|
||||
|
||||
int samples = 0, min = int.MaxValue;
|
||||
long total = 0;
|
||||
for (var ms = 0; ms < 120_000; ms += 100)
|
||||
{
|
||||
clock.Advance(TimeSpan.FromMilliseconds(100));
|
||||
world.Tick();
|
||||
if (ms < 10_000) continue; // il primo ciclo parte da scadenze sparse
|
||||
var nowMs = world.NowUnixMs;
|
||||
var critical = world.Auctions.Count(a => active.Contains(a.Id) && a.Status == "ON" && a.Started
|
||||
&& a.ExpiryUnix * 1000 - nowMs is > 0 and < 4000);
|
||||
samples++;
|
||||
total += critical;
|
||||
min = Math.Min(min, critical);
|
||||
}
|
||||
Assert.True(min >= 10, $"nel momento peggiore solo {min} aste in Attiva sotto i 4 s (in media {(double)total / samples:0.#})");
|
||||
Assert.DoesNotContain(seeded, a => a.Status == "OFF");
|
||||
}
|
||||
|
||||
private static SimWorld NewWorld(SimulatorPlan plan, int seed, out FakeClock clock)
|
||||
{
|
||||
var c = new FakeClock(new DateTimeOffset(2026, 11, 27, 12, 0, 0, TimeSpan.Zero));
|
||||
var world = new SimWorld(seed, () => c.Now, populate: false) { TargetAuctions = plan.WorldAuctions, FixedFreqSeconds = plan.FreqSeconds, EndlessAuctions = plan.Load };
|
||||
world.Populate();
|
||||
clock = c;
|
||||
return world;
|
||||
}
|
||||
|
||||
private sealed class FakeClock(DateTimeOffset start)
|
||||
{
|
||||
public DateTimeOffset Now { get; private set; } = start;
|
||||
public void Advance(TimeSpan by) => Now += by;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user