E5: il giro non si ripete a vuoto e le copie automatiche cedono davvero

Il passaggio che segue la ripresa di un giro non rifà il lavoro di
recupero (prova delle cartelle in pausa, ripresa dei lavori fermati da
un errore): un lavoro che si ferma di nuovo aspetta il giro dopo invece
di essere ripreso all'infinito senza dormire. Il giro misura lo spazio
per il lavoro automatico che riprenderebbe, non per una pausa di Alberto,
così una pausa per spazio non va e viene con un evento nuovo ogni volta.
«Annulla» tiene lontane le partenze automatiche finché il lavoro è
annullato; «Esporta questo account» spento ferma subito la copia
automatica; «Cerca i video fermi» chiede di fermarsi a una copia
automatica partita dopo di lei; un file che manca sul disco non crea
più un lavoro automatico a ogni passaggio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-04 19:42:27 +01:00
1 parent 93f7978d9e
commit 309f4d0402
12 files changed
+436 -32

No files matched your search

@@ -635,6 +635,75 @@ public sealed class ExportServiceAutomaticTests
Assert.AreEqual(ExportRunState.Completed, (await bed.RunAsync(start.Runs[0].Id, ct)).State);
}
/// <summary>
/// «Esporta questo account» turned off stops the automatic job at once (its run «interrotto», no error), and the run
/// resumed with the switch read again skips the account's files: none of them is written after the switch.
/// </summary>
[TestMethod]
public async Task TurningAnAccountOffStopsTheAutomaticJobAndItsFilesAreSkipped()
{
var ct = TestContext.CancellationToken;
var held = new HeldExportFileSystem(p => p.EndsWith("_1.jpg", StringComparison.Ordinal) && p.Contains("l01", StringComparison.Ordinal));
await using var bed = await ExportTestBed.CreateAsync(env => env with { FileSystem = held });
var first = await bed.PostAsync(bed.Luca, "l01", 1);
var second = await bed.PostAsync(bed.Luca, "l02", 2);
var auto = await TurnOnAsync(bed, await bed.GeneralAsync(ct: ct), ct);
var run = (await bed.Service.TryStartAutomaticAsync(Selection(auto, round: true), ct)).Runs.Single();
await held.Reached.Task.WaitAsync(Patience, ct);
await bed.Service.SetAccountExportEnabledAsync(bed.Luca.Id, enabled: false, ct);
Assert.IsFalse(bed.Service.IsBusy, "the automatic job was stopped");
var stopped = await bed.RunAsync(run.Id, ct);
Assert.AreEqual((ExportRunState.Interrupted, (string?)null), (stopped.State, stopped.LastError));
held.Release();
Assert.AreEqual(AutoExportStartOutcome.Started, (await bed.Service.TryResumeAutomaticAsync([run.Id], ct)).Outcome);
await bed.Service.WaitAsync(ct);
Assert.AreEqual(ExportRunState.Completed, (await bed.RunAsync(run.Id, ct)).State);
Assert.IsFalse(File.Exists(bed.GeneralCopy(bed.Luca, first.Media[0])));
Assert.IsFalse(File.Exists(bed.GeneralCopy(bed.Luca, second.Media[0])));
Assert.IsEmpty(await bed.Db.Exports.ListCopiesAsync(auto.Id, ct: ct));
}
/// <summary>
/// «Annulla» of an automatic run keeps automatic starts away until the run is «annullato»: the worker's resume of the
/// same run in that moment is refused (Busy), so the run stays «annullato» and nothing is copied.
/// </summary>
[TestMethod]
public async Task DiscardOfAnAutomaticRunCannotRaceItsResume()
{
var ct = TestContext.CancellationToken;
var held = new HeldExportFileSystem(p => p.EndsWith("_1.jpg", StringComparison.Ordinal));
await using var bed = await ExportTestBed.CreateAsync(env => env with { FileSystem = held });
var post = await bed.PostAsync(bed.Luca, "d01", 1);
var auto = await TurnOnAsync(bed, await bed.GeneralAsync(ct: ct), ct);
var run = (await bed.Service.TryStartAutomaticAsync(Selection(auto, round: true), ct)).Runs.Single();
await held.Reached.Task.WaitAsync(Patience, ct);
Assert.IsTrue(await bed.Service.InterruptAutomaticAsync(ct));
await bed.Service.WaitAsync(ct);
held.Release();
Assert.AreEqual(ExportRunState.Interrupted, (await bed.RunAsync(run.Id, ct)).State);
var reached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var go = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
bed.Service.DiscardChecked = async token =>
{
reached.TrySetResult();
await go.Task.WaitAsync(token);
};
var discard = bed.Service.DiscardAsync(run.Id, ct);
await reached.Task.WaitAsync(Patience, ct);
Assert.AreEqual(AutoExportStartOutcome.Busy, (await bed.Service.TryResumeAutomaticAsync([run.Id], ct)).Outcome);
go.SetResult();
await discard;
await bed.Service.WaitAsync(ct);
Assert.AreEqual(ExportRunState.Cancelled, (await bed.RunAsync(run.Id, ct)).State);
Assert.IsFalse(File.Exists(bed.GeneralCopy(bed.Luca, post.Media[0])));
bed.Service.DiscardChecked = null;
Assert.AreEqual(AutoExportStartOutcome.NothingToDo, (await bed.Service.TryResumeAutomaticAsync([run.Id], ct)).Outcome, "after «Annulla» the gate is open again");
}
/// <summary>
/// The automatic export resumes only automatic runs: a manual «In pausa» stays Alberto's even when its folder
/// answers again (answer 48); «Riprova» resumes it.