|
| 1 | +using SIL.Motif.App; |
| 2 | +using SIL.Motif.App.Services; |
| 3 | +using SIL.Motif.App.ViewModels; |
| 4 | +using SIL.Motif.Commands; |
| 5 | +using SIL.Motif.Commands.Baselines; |
| 6 | +using SIL.Motif.Contract.Ids; |
| 7 | +using SIL.Motif.Contract.Requests; |
| 8 | +using SIL.Motif.Contract.Responses; |
| 9 | +using SIL.Motif.Host; |
| 10 | +using SIL.Motif.Tests.Parser; |
| 11 | +using SIL.Motif.Tests.TestFixtures; |
| 12 | +using Xunit; |
| 13 | + |
| 14 | +namespace SIL.Motif.Tests.App.Walkthrough; |
| 15 | + |
| 16 | +/// <summary>Switches every page and Texts tab over the 3000-word large fixture with the trace on (opt-in, MOTIF_PERF=1).</summary> |
| 17 | +[Collection(LcmCacheTestCollection.Name)] |
| 18 | +[Trait("MotifTestLevel", "System")] |
| 19 | +[Trait("Category", "Perf")] |
| 20 | +public sealed class LargeProjectViewSwitchPerfTests |
| 21 | +{ |
| 22 | + [PerfFact] |
| 23 | + public void EveryPageAndViewSwitchesOverTheLargeProject() |
| 24 | + { |
| 25 | + var path = Environment.GetEnvironmentVariable("MOTIF_PERF_TRACE") |
| 26 | + ?? Path.Combine(Path.GetTempPath(), "motif-perf-large-trace.jsonl"); |
| 27 | + File.Delete(path); |
| 28 | + var warmPasses = int.TryParse(Environment.GetEnvironmentVariable("MOTIF_PERF_N"), out var n) && n > 0 ? n : 3; |
| 29 | + AvaloniaHeadlessFixture.RunUntilComplete(async () => |
| 30 | + { |
| 31 | + using var project = new LargeProjectFixture(); |
| 32 | + var parser = FakeParser.CopyRecordingInvocations(project.ManagedRoot); |
| 33 | + FakeParser.BehaveBesideExecutable(parser, new |
| 34 | + { |
| 35 | + words = project.Words.Select((word, index) => new |
| 36 | + { |
| 37 | + word = word.Form, |
| 38 | + outcome = index % 5 == 0 ? "capped" : index % 5 == 1 ? "no-analysis" : "complete", |
| 39 | + elapsedMs = 1 + index % 20, |
| 40 | + analyses = index % 5 < 2 ? Array.Empty<object>() : new object[] |
| 41 | + { |
| 42 | + new { morphs = new[] { new |
| 43 | + { |
| 44 | + form = word.AllomorphId.ToString("D"), msa = word.MsaId.ToString("D"), |
| 45 | + inflType = (string?)null, guessedString = (string?)null, |
| 46 | + } } }, |
| 47 | + }, |
| 48 | + }), |
| 49 | + }); |
| 50 | + var client = RealCommandClient.Create(project.ManagedRoot, parser); |
| 51 | + Assert.True((await client.CaptureBaselineAsync(new BaselineCaptureRequest(project.FwDataPath), CancellationToken.None)).Succeeded); |
| 52 | + Assert.True((await client.SetDefaultSelectionAsync(new SetDefaultSelectionRequest( |
| 53 | + project.FwDataPath, "Large Selection", project.TextIds, []), CancellationToken.None)).Succeeded); |
| 54 | + Assert.True((await client.SkipSetupAsync(new SkipSetupRequest(project.FwDataPath), CancellationToken.None)).Succeeded); |
| 55 | + Assert.True((await client.AssessAsync(new AssessRequest(project.FwDataPath), |
| 56 | + new Progress<AssessmentProgress>(), CancellationToken.None)).Succeeded); |
| 57 | + var pending = await client.LoadPendingChangesAsync( |
| 58 | + new PendingChangesRequest(project.FwDataPath, MotifProductVersion.CurrentText), CancellationToken.None); |
| 59 | + var revision = pending.Value!.Revision; |
| 60 | + foreach (var word in project.Words.Take(200)) |
| 61 | + { |
| 62 | + var put = await client.PutPendingChangeAsync(new PutPendingChangeRequest( |
| 63 | + project.FwDataPath, MotifProductVersion.CurrentText, revision, |
| 64 | + new ChangeIntent(CanonicalId.Mint().Value, "incorrect-spelling", |
| 65 | + CanonicalId.FromGuid(word.WordformId).Value, word.Form)), CancellationToken.None); |
| 66 | + revision = put.Value!.Revision; |
| 67 | + } |
| 68 | + using var window = new WalkthroughWindow(project.ManagedRoot, project.FwDataPath, parserPath: parser); |
| 69 | + window.Show(); |
| 70 | + window.OpenRecentProjectByClick(project.FwDataPath); |
| 71 | + await window.Workspace.Context.EvidencePublication; |
| 72 | + window.WaitUntilProjectIsQuiet(TimeSpan.FromSeconds(60), "large project did not finish opening"); |
| 73 | + window.ShowPage(WorkspacePage.Overview); |
| 74 | + PageScreenshots.Settle(window.Window); |
| 75 | + // Prime the Texts reader, as a user who has opened Texts once would have. |
| 76 | + window.ShowPage(WorkspacePage.Texts); |
| 77 | + window.WaitUntil(() => window.Workspace.PageModel<TextsPageModel>().ResultsInText.Texts.Count == LargeProjectFixture.TextCount, |
| 78 | + TimeSpan.FromSeconds(60), "the large Texts were not loaded"); |
| 79 | + window.ShowPage(WorkspacePage.Overview); |
| 80 | + PageScreenshots.Settle(window.Window); |
| 81 | + |
| 82 | + using var sink = MotifTrace.StartListening(path); |
| 83 | + for (var pass = 0; pass <= warmPasses; pass++) |
| 84 | + { |
| 85 | + MotifTrace.RunLabel = $"{(pass == 0 ? "cold" : "warm")} large"; |
| 86 | + foreach (var (name, page, tab) in PageScreenshots.Views()) |
| 87 | + await ViewSwitchPerfTests.Switch(window.Workspace, window.Window, name, page, tab); |
| 88 | + } |
| 89 | + MotifTrace.RunLabel = null; |
| 90 | + }, TimeSpan.FromMinutes(20)); |
| 91 | + } |
| 92 | +} |
0 commit comments