E5: il posto per il prossimo file è quello del file che la copia scrive

La sonda di «Riprova» e del giro misurava il file della libreria, mentre
la copia controlla il file che scrive: una foto che diventa un PNG più
grande toglieva la pausa, la copia si fermava di nuovo e ogni ora c'era
un evento «in pausa» in più; un PNG che diventa un JPG più piccolo non
ripartiva mai; per un fotogramma serviva il posto di tutto il video.

Ora la copia ricorda in memoria quanto ha chiesto al disco quando si è
fermata (ExportCopier.SpaceNeeded) e la sonda usa quella misura per il
primo elemento in attesa di ogni lavoro in pausa
(ListNextPendingFilesAsync); senza misura, dopo un riavvio, il file
della libreria e per un fotogramma il solo margine.

Il giro di una cartella automatica guarda solo i lavori automatici che
riprenderebbe, come dice la specifica (§4.10): senza lavori automatici
in pausa basta che la cartella risponda, e una copia grande di Alberto
in pausa non blocca più i file nuovi che ci stanno (risposta 48). In una
cartella non automatica il giro non riprende nulla e misura come
«Riprova».

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-04 21:16:35 +01:00
1 parent 248b82b590
commit c3d9e02e22
9 files changed
+266 -68

No files matched your search

@@ -3,6 +3,7 @@ using Febe.Core.Abstractions;
using Febe.Core.Domain;
using Febe.Core.Export;
using Febe.Core.Storage;
using Febe.Tests.Codecs.Containers;
using Febe.Tests.Export.Support;
using Febe.Tests.Support;
@@ -826,6 +827,71 @@ public sealed class ExportServiceAutomaticTests
Assert.AreEqual(1, (await bed.Db.Events.ListAsync(new() { Limit = 100 }, ct)).Count(e => e.Code == ExportPause.PausedEventCode));
}
/// <summary>
/// D11 with a converted file: the probe measures the file the copy writes, which the copier measured when it paused,
/// not the library file. A PNG that becomes a smaller JPG resumes as soon as the JPG fits.
/// </summary>
[TestMethod]
public async Task ProbeMeasuresTheConvertedFileTheJobWrites()
{
var ct = TestContext.CancellationToken;
await using var bed = await ExportTestBed.CreateAsync();
using var picture = TestImages.Scene(7, 320, 240);
var post = await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "c01", Make.T0.AddDays(-1)), [new TestFile(Make.Photo(1), TestImages.Png(picture), ".png")]);
var usb = await bed.GeneralAsync(ct: ct);
await bed.Service.Destinations.UpdateAsync(usb.Id, Spec(bed, usb) with { PhotoFormat = ExportFormat.Jpg }, ct);
bed.Disk.Free = ExportSpace.Margin / 2;
var run = (await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([post.Media[0].Id])), ct)).Runs.Single();
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(run.Id, ct)).State);
var item = (await bed.ItemsAsync(run.Id, ct)).Single();
var jpg = bed.Service.Copier.SpaceNeeded(run.Id, item.Id);
Assert.IsNotNull(jpg);
Assert.IsLessThan(post.Media[0].Bytes!.Value, jpg.Value, "the JPG is smaller than its PNG");
bed.Disk.Free = ExportSpace.Margin + jpg.Value - 1;
StringAssert.Contains((await bed.Service.RetryDestinationAsync(usb.Id, ct)).Problem, "per il prossimo file");
bed.Disk.Free = ExportSpace.Margin + jpg.Value;
var retry = await bed.Service.RetryDestinationAsync(usb.Id, ct);
await bed.Service.WaitAsync(ct);
Assert.IsNull(retry.Problem);
Assert.AreEqual(ExportRunState.Completed, (await bed.RunAsync(run.Id, ct)).State);
Assert.AreEqual(1, (await bed.Db.Events.ListAsync(new() { Limit = 100 }, ct)).Count(e => e.Code == ExportPause.PausedEventCode));
}
/// <summary>
/// D11 with a frames job: the room asked is the frame's, never the whole video's; after a restart (the measure is in
/// memory) the frame's size is not known and only the margin counts, without a size in the reason.
/// </summary>
[TestMethod]
public async Task ProbeOfAFramesJobMeasuresTheFrameNotTheVideo()
{
var ct = TestContext.CancellationToken;
await using var bed = await ExportTestBed.CreateAsync();
var video = (await bed.Library.SaveAsync(
bed.Marta,
Make.Entry(bed.Marta.Id, "f01", Make.T0.AddDays(-2)),
[new TestFile(Make.Video(1) with { Duration = null }, TestVideos.Mp4(ElementaryStream.Load("BA1_Sony_D")), ".mp4")])).Media[0];
var usb = await bed.GeneralAsync(ct: ct);
bed.Disk.Free = ExportSpace.Margin / 2;
var request = new ExportJobRequest(new ExportSelection.Media([video.Id]), Frames: new ExportFramesRequest(FrameMode.At, TimeSpan.Zero, null, null, ExportFormat.Jpg));
var run = (await bed.CopyAsync(request, ct)).Runs.Single();
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(run.Id, ct)).State);
var frame = bed.Service.Copier.SpaceNeeded(run.Id, (await bed.ItemsAsync(run.Id, ct)).Single().Id);
Assert.IsNotNull(frame);
bed.Disk.Free = ExportSpace.Margin + frame.Value - 1;
Assert.IsNotNull(await bed.Service.ProbeDestinationAsync(usb.Id, ct));
// After a restart: the video's size does not count (it would ask for more than a frame needs).
await using var restarted = new ExportService(bed.Environment);
bed.Disk.Free = ExportSpace.Margin - 1;
var problem = await restarted.ProbeDestinationAsync(usb.Id, ct);
StringAssert.Contains(problem, "per il prossimo file serve più spazio");
bed.Disk.Free = ExportSpace.Margin;
Assert.IsNull(await restarted.ProbeDestinationAsync(usb.Id, ct));
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(run.Id, ct)).State, "the probe resumes nothing");
}
/// <summary>The end of Febe stops the job and waits until its states are saved.</summary>
[TestMethod]
public async Task DisposeAwaitsARunningJob()