E4: prove dei video fermi e dimostrazione a ogni ora
Completa l'elenco di prove del progetto: analizzatore (grana, luce che pulsa, foto notturna, contenitori, durata sconosciuta, flussi rovinati), servizio (lavori lunghi, file spariti o cambiati, errori, «Interrompi», chiusura), copie del fotogramma (pausa e ripresa, validazione, video sempre intero), API (selezioni, stesso file, eventi) e l'interfaccia vera nel browser: visualizzatore, «Salva il fotogramma», «Cerca i video fermi», Dashboard e filtro «Video fermi». Le prove hanno trovato che la dimostrazione dipendeva dall'ora: la storia ferma poteva avere la copertina del video fermo di marta (un file solo invece di due) e il video «Non analizzabile» poteva mancare. Ora la storia è su un'altra immagine e, se le immagini senza copie non bastano, si usano quelle di foto copiate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eea4394a0f
commit
066addbc84
10 files changed
+1100
-18
No files matched your search
@@ -360,8 +360,275 @@ public sealed class StillVideoServiceTests
|
||||
Assert.AreEqual((2, 1, 1), (service.Progress.Done, service.Progress.Still, service.Progress.Moving));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(LongWorkKind.Import)]
|
||||
[DataRow(LongWorkKind.Export)]
|
||||
[DataRow(LongWorkKind.Rebuild)]
|
||||
[DataRow(LongWorkKind.FrameDownload)]
|
||||
public async Task TheJobNeverWorksTogetherWithALongWork(LongWorkKind kind)
|
||||
{
|
||||
// Answer 41: import, copies and rebuild (and a zip of frames); the one that starts during an analysis is never
|
||||
// made to wait: the job gives its video up.
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, video) = await SaveVideoAsync(library, "1", StillVideo(20));
|
||||
var gate = new LongWorkGate();
|
||||
var blocker = new Blocker(library.Layout.FullPath(account, video.RelativePath!));
|
||||
using var service = new StillVideoService(Environment(library, gate) with { Analyser = blocker.Analyse });
|
||||
|
||||
await service.StartAsync(new ExportSelection.Account(account.Id), ct);
|
||||
await blocker.Started.Task.WaitAsync(Patience, ct);
|
||||
Assert.IsTrue(gate.TryEnter(kind, out var lease, out _), "the job holds no lease");
|
||||
using (lease)
|
||||
{
|
||||
await blocker.Cancelled.Task.WaitAsync(Patience, ct);
|
||||
await UntilAsync(() => service.Progress.Waiting == StillVideoText.LongWork && service.Progress.CurrentMediaId is null, ct);
|
||||
Assert.IsNull(await library.Db.VideoAnalyses.GetAsync(video.Sha256!, ct));
|
||||
Assert.AreEqual((true, 0, 1), (service.Progress.Running, service.Progress.Done, blocker.Calls));
|
||||
}
|
||||
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
Assert.AreEqual((1, 1, 2), (service.Progress.Done, service.Progress.Still, blocker.Calls));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AFileGoneOrChangedIsSkippedAndTheJobGoesOn()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, first) = await SaveVideoAsync(library, "1", StillVideo(21));
|
||||
var (_, gone) = await SaveVideoAsync(library, "2", StillVideo(22));
|
||||
var (_, changed) = await SaveVideoAsync(library, "3", StillVideo(23));
|
||||
var (_, replaced) = await SaveVideoAsync(library, "4", StillVideo(24));
|
||||
var (_, last) = await SaveVideoAsync(library, "5", MovingVideo());
|
||||
var calls = new ConcurrentQueue<string>();
|
||||
var blocker = new Blocker(library.Layout.FullPath(account, first.RelativePath!), cancelOnly: false);
|
||||
using var service = new StillVideoService(Environment(library) with
|
||||
{
|
||||
Analyser = (path, budget, token) =>
|
||||
{
|
||||
calls.Enqueue(path);
|
||||
return blocker.Analyse(path, budget, token);
|
||||
},
|
||||
});
|
||||
|
||||
// While the first one is analysed: a file goes, one changes on disk, one is replaced in the database («Tieni il più
|
||||
// grande», a rebuild), so that its old analysis would be of another file.
|
||||
await service.StartAsync(new ExportSelection.Account(account.Id), ct);
|
||||
await blocker.Started.Task.WaitAsync(Patience, ct);
|
||||
File.Delete(library.Layout.FullPath(account, gone.RelativePath!));
|
||||
await File.WriteAllBytesAsync(library.Layout.FullPath(account, changed.RelativePath!), StillVideo(25), ct);
|
||||
await library.Db.Media.UpdateAsync((await library.Db.Media.GetAsync(replaced.Id, ct))! with { Sha256 = Make.Sha(77) }, ct);
|
||||
blocker.Release();
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
|
||||
var progress = service.Progress;
|
||||
Assert.AreEqual((5, 5, 1, 1, 0, 3), (progress.Total, progress.Done, progress.Still, progress.Moving, progress.NotAnalyzable, progress.Skipped));
|
||||
Assert.AreEqual("Analizzati 2 video: 1 fermo, 1 in movimento, 3 saltati", StillVideoText.Summary(progress));
|
||||
Assert.HasCount(2, calls, "only the files that are the ones recorded are analysed");
|
||||
foreach (var sha in new[] { gone.Sha256!, changed.Sha256!, replaced.Sha256!, Make.Sha(77) })
|
||||
{
|
||||
Assert.IsNull(await library.Db.VideoAnalyses.GetAsync(sha, ct), "nothing is stored for a video left out");
|
||||
}
|
||||
|
||||
Assert.IsNotNull(await library.Db.VideoAnalyses.GetAsync(last.Sha256!, ct));
|
||||
|
||||
// Put back, the changed one is analysed when asked again: nothing said it was done.
|
||||
Assert.AreEqual(3, (await service.PlanAsync(new ExportSelection.Account(account.Id), ct)).ToAnalyse);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AnUnexpectedErrorSkipsTheVideoAndTheLogHasNoPath()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, first) = await SaveVideoAsync(library, "1", StillVideo(26));
|
||||
var (_, second) = await SaveVideoAsync(library, "2", MovingVideo());
|
||||
var firstPath = library.Layout.FullPath(account, first.RelativePath!);
|
||||
var log = new ConcurrentQueue<string>();
|
||||
using var service = new StillVideoService(Environment(library) with
|
||||
{
|
||||
Log = log.Enqueue,
|
||||
Analyser = (path, budget, token) => path == firstPath
|
||||
? throw new InvalidOperationException("guasto in " + path)
|
||||
: RealAnalysis(path, budget, token),
|
||||
});
|
||||
|
||||
await service.StartAsync(new ExportSelection.Account(account.Id), ct);
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
|
||||
Assert.AreEqual((2, 1, 1), (service.Progress.Done, service.Progress.Moving, service.Progress.Skipped));
|
||||
Assert.IsNull(await library.Db.VideoAnalyses.GetAsync(first.Sha256!, ct));
|
||||
Assert.IsNotNull(await library.Db.VideoAnalyses.GetAsync(second.Sha256!, ct));
|
||||
var line = log.Single();
|
||||
Assert.AreEqual("Un video non si è potuto analizzare (InvalidOperationException).", line, "the type only: no path, no message (rule 10)");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AVideoAnalysedFromTheViewerMeanwhileIsCountedNotAnalysedAgain()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, video) = await SaveVideoAsync(library, "1", StillVideo(27));
|
||||
var session = new FakeSessionState { InSession = true };
|
||||
var calls = new ConcurrentQueue<string>();
|
||||
using var service = new StillVideoService(Environment(library) with { Session = session, Analyser = Counting(calls) });
|
||||
|
||||
await service.StartAsync(new ExportSelection.Account(account.Id), ct);
|
||||
await UntilAsync(() => service.Progress.Waiting == StillVideoText.InSession, ct);
|
||||
Assert.AreEqual(StillVideoAnswerKind.Analysed, (await service.AnalyseNowAsync(video.Id, ct)).Kind, "the viewer does not wait for the session (answer 43)");
|
||||
session.InSession = false;
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
|
||||
Assert.HasCount(1, calls);
|
||||
Assert.AreEqual((1, 1, 1), (service.Progress.Total, service.Progress.Done, service.Progress.Still));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheViewerAnalysesOneVideoAtATimeAndACancelledRequestStoresNothing()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, first) = await SaveVideoAsync(library, "1", StillVideo(28));
|
||||
var (_, second) = await SaveVideoAsync(library, "2", MovingVideo());
|
||||
var blocker = new Blocker(library.Layout.FullPath(account, first.RelativePath!));
|
||||
var atWork = 0;
|
||||
var most = 0;
|
||||
using var service = new StillVideoService(Environment(library) with
|
||||
{
|
||||
Analyser = (path, budget, token) =>
|
||||
{
|
||||
var now = Interlocked.Increment(ref atWork);
|
||||
InterlockedMax(ref most, now);
|
||||
try
|
||||
{
|
||||
return blocker.Analyse(path, budget, token);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref atWork);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
using var closed = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
var one = service.AnalyseNowAsync(first.Id, closed.Token);
|
||||
await blocker.Started.Task.WaitAsync(Patience, ct);
|
||||
var two = service.AnalyseNowAsync(second.Id, ct);
|
||||
Assert.IsFalse(two.IsCompleted, "the second waits for the first");
|
||||
|
||||
// The page that asked the first closed: its request ends, nothing is stored, and the second is answered.
|
||||
await closed.CancelAsync();
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(() => one);
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, (await two.WaitAsync(Patience, ct)).Analysis!.Outcome);
|
||||
Assert.IsNull(await library.Db.VideoAnalyses.GetAsync(first.Sha256!, ct));
|
||||
Assert.AreEqual(1, Volatile.Read(ref most));
|
||||
Assert.AreEqual(StillVideoAnswerKind.Analysed, (await service.AnalyseNowAsync(first.Id, ct)).Kind, "asked again, it is analysed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AFileKeepsItsAnalysisUnderEveryEntryAndLosesItWhenItIsAnother()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, first) = await SaveVideoAsync(library, "1", StillVideo(29));
|
||||
using var service = new StillVideoService(Environment(library));
|
||||
Assert.AreEqual(StillVideoAnswerKind.Analysed, (await service.AnalyseNowAsync(first.Id, ct)).Kind);
|
||||
|
||||
// The same file under an entry added later (an import): already analysed, with no work.
|
||||
var again = (await library.Db.Entries.AddAsync(
|
||||
Make.Entry(account.Id, "9", Make.T0.AddMinutes(9)), [Make.Stored(Make.Video(1), first.Sha256!, first.RelativePath!)], ct)).Stored;
|
||||
var plan = await service.PlanAsync(new ExportSelection.Entries([again.Entry.Id]), ct);
|
||||
Assert.AreEqual((0, 1), (plan.ToAnalyse, plan.AlreadyAnalysed));
|
||||
|
||||
// A row of an algorithm newer than this Febe's (a database opened by a later version first): not analysed again.
|
||||
await library.Db.VideoAnalyses.SetAsync(new VideoAnalysis(first.Sha256!, StillVideoAnalyzer.Algorithm + 1, VideoAnalysisOutcome.Moving, Make.T0), ct);
|
||||
Assert.AreEqual(0, (await service.PlanAsync(new ExportSelection.Account(account.Id), ct)).ToAnalyse);
|
||||
|
||||
// Another file in its place: its SHA-256 has no analysis, so it is to analyse.
|
||||
await library.Db.Media.UpdateAsync((await library.Db.Media.GetAsync(first.Id, ct))! with { Sha256 = Make.Sha(78) }, ct);
|
||||
plan = await service.PlanAsync(new ExportSelection.Media([first.Id]), ct);
|
||||
Assert.AreEqual((1, 0), (plan.ToAnalyse, plan.AlreadyAnalysed));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task InterrompiWhileItWaitsEndsTheJobAndANewOneStartsFromZero()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, video) = await SaveVideoAsync(library, "1", StillVideo(30));
|
||||
var session = new FakeSessionState { InSession = true };
|
||||
using var service = new StillVideoService(Environment(library) with { Session = session });
|
||||
var selection = new ExportSelection.Account(account.Id);
|
||||
|
||||
Assert.IsFalse(service.Stop().Stopped, "nothing to stop");
|
||||
await service.StartAsync(selection, ct);
|
||||
await UntilAsync(() => service.Progress.Waiting == StillVideoText.InSession, ct);
|
||||
service.Stop();
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
Assert.AreEqual((false, true, 1, 0), (service.Progress.Running, service.Progress.Stopped, service.Progress.Total, service.Progress.Done));
|
||||
Assert.IsNull(service.Progress.Waiting);
|
||||
|
||||
session.InSession = false;
|
||||
var started = await service.StartAsync(selection, ct);
|
||||
Assert.AreEqual((true, false, 1, 0), (started.Running, started.Stopped, started.Total, started.Done));
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
Assert.AreEqual((1, 1, false), (service.Progress.Done, service.Progress.Still, service.Progress.Stopped));
|
||||
Assert.IsNotNull(await library.Db.VideoAnalyses.GetAsync(video.Sha256!, ct));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ClosingFebeLeavesTheVideoAtWorkAndStoresNothing()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
var (account, video) = await SaveVideoAsync(library, "1", StillVideo(31));
|
||||
var blocker = new Blocker(library.Layout.FullPath(account, video.RelativePath!));
|
||||
var service = new StillVideoService(Environment(library) with { Analyser = blocker.Analyse });
|
||||
await service.StartAsync(new ExportSelection.Account(account.Id), ct);
|
||||
await blocker.Started.Task.WaitAsync(Patience, ct);
|
||||
|
||||
service.Dispose();
|
||||
service.Dispose();
|
||||
await service.Job.WaitAsync(Patience, ct);
|
||||
|
||||
Assert.IsFalse(service.Progress.Running);
|
||||
Assert.IsNull(await library.Db.VideoAnalyses.GetAsync(video.Sha256!, ct));
|
||||
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(() => service.AnalyseNowAsync(video.Id, ct));
|
||||
await Assert.ThrowsExactlyAsync<ObjectDisposedException>(() => service.StartAsync(new ExportSelection.Account(account.Id), ct));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheTextsCountInItalian()
|
||||
{
|
||||
// The confirmation and the end of the job, one and many (the words of the design, questions 41 and 44).
|
||||
Assert.AreEqual("28 video da analizzare · 12 già analizzati · le 5 foto si saltano", StillVideoText.PlanSummary(new StillVideoPlan(28, 12, 5, 0)));
|
||||
Assert.AreEqual("1 video da analizzare · 1 già analizzato · la foto si salta · 1 video non presente in libreria", StillVideoText.PlanSummary(new StillVideoPlan(1, 1, 1, 1)));
|
||||
Assert.AreEqual("1.200 video da analizzare · 3 video non presenti in libreria", StillVideoText.PlanSummary(new StillVideoPlan(1200, 0, 0, 3)));
|
||||
StillVideoProgress Ended(int still, int moving, int not, int skipped) => new(false, still + moving + not + skipped, still + moving + not + skipped, still, moving, not, skipped, false, null, null);
|
||||
Assert.AreEqual("Analizzati 28 video: 3 fermi, 24 in movimento, 1 non analizzabile", StillVideoText.Summary(Ended(3, 24, 1, 0)));
|
||||
Assert.AreEqual("Analizzato 1 video: 1 fermo, 0 in movimento, 1 saltato", StillVideoText.Summary(Ended(1, 0, 0, 1)));
|
||||
Assert.AreEqual("Analizzati 2 video: 0 fermi, 0 in movimento, 2 non analizzabili, 2 saltati", StillVideoText.Summary(Ended(0, 0, 2, 2)));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------- helpers
|
||||
|
||||
private static void InterlockedMax(ref int target, int value)
|
||||
{
|
||||
int seen;
|
||||
while ((seen = Volatile.Read(ref target)) < value && Interlocked.CompareExchange(ref target, value, seen) != seen)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] StillVideo(int seed, bool audio = false)
|
||||
{
|
||||
var photo = PcmVideos.Photo(seed);
|
||||
|
||||
Reference in new issue
Block a user