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:
1 parent
248b82b590
commit
c3d9e02e22
9 files changed
+266
-68
No files matched your search
@@ -531,6 +531,92 @@ public sealed class AutoExportWorkerTests
|
||||
Assert.AreEqual(events, await PauseEventsAsync(bed, ct));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// D11 with a converted file: the round measures the file the automatic run writes (a JPEG that becomes a larger
|
||||
/// PNG), not the library file. With room for the JPEG only, the pause stays and no event is added at each round; with
|
||||
/// room for the PNG, the run resumes and ends.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public async Task TheRoundMeasuresTheConvertedFileOfTheAutomaticRun()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var post = await bed.Library.SaveAsync(bed.Luca, Make.Entry(bed.Luca.Id, "p01", Make.T0.AddDays(-1)), [TestFile.Photo(1, 3, 200, 250)]);
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
usb = (await bed.Service.Destinations.UpdateAsync(usb.Id, Spec(usb) with { Automatic = true, OnlyNew = false, PhotoFormat = ExportFormat.Png }, ct)).Destination;
|
||||
var worker = Worker(bed);
|
||||
bed.Disk.Free = ExportSpace.Margin / 2;
|
||||
Assert.AreEqual(AutoExportPass.Started, await worker.RunOnceAsync(round: false, ct));
|
||||
await bed.Service.WaitAsync(ct);
|
||||
var run = (await bed.Db.Exports.ListRunsAsync(ct)).Single();
|
||||
Assert.AreEqual(ExportRunState.Paused, run.State);
|
||||
var png = bed.Service.Copier.SpaceNeeded(run.Id, (await bed.ItemsAsync(run.Id, ct)).Single().Id);
|
||||
var jpeg = post.Media[0].Bytes!.Value;
|
||||
Assert.IsNotNull(png);
|
||||
Assert.IsGreaterThan(jpeg, png.Value, "the PNG is larger than its JPEG");
|
||||
var events = await PauseEventsAsync(bed, ct);
|
||||
|
||||
bed.Disk.Free = ExportSpace.Margin + jpeg + 10;
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
bed.Clock.Now += TimeSpan.FromHours(1);
|
||||
Assert.AreEqual(AutoExportPass.NothingToDo, await worker.RunOnceAsync(round: true, ct));
|
||||
}
|
||||
|
||||
Assert.AreEqual(events, await PauseEventsAsync(bed, ct), "no new pause event at each round");
|
||||
Assert.IsNotNull((await bed.Db.Exports.GetDestinationAsync(usb.Id, ct))!.PausedAt);
|
||||
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(run.Id, ct)).State);
|
||||
|
||||
bed.Disk.Free = ExportSpace.Margin + png.Value;
|
||||
bed.Clock.Now += TimeSpan.FromHours(1);
|
||||
Assert.AreEqual(AutoExportPass.Started, await worker.RunOnceAsync(round: true, ct));
|
||||
await bed.Service.WaitAsync(ct);
|
||||
Assert.AreEqual(ExportRunState.Completed, (await bed.RunAsync(run.Id, ct)).State);
|
||||
Assert.AreEqual(events, await PauseEventsAsync(bed, ct));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spec §4.10: in an automatic folder the round does not measure a paused job of Alberto's. His large copy paused for
|
||||
/// space does not keep the folder paused for the new files that fit (they are copied, his job stays «In pausa»,
|
||||
/// answer 48); in a folder that is not automatic the round resumes nothing and measures as «Riprova»: the pause stays,
|
||||
/// with no new event.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public async Task APausedJobOfAlbertosDoesNotKeepAnAutomaticFolderPaused()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var bigLuca = await bed.Library.SaveAsync(bed.Luca, Make.Entry(bed.Luca.Id, "b01", Make.T0.AddDays(-1)), [TestFile.Photo(1, 3, 400, 500)]);
|
||||
var bigMarta = await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "b02", Make.T0.AddDays(-1)), [TestFile.Photo(1, 4, 400, 500)]);
|
||||
bed.Clock.Now += TimeSpan.FromMinutes(1);
|
||||
var usb = await TurnOnAsync(bed, await bed.GeneralAsync(ct: ct), onlyNew: true, ct);
|
||||
var nas = await bed.OwnAsync(bed.Marta, "marta-nas", ct: ct);
|
||||
bed.Disk.Free = ExportSpace.Margin / 2;
|
||||
var luca = (await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([bigLuca.Media[0].Id])), ct)).Runs.Single();
|
||||
var marta = (await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([bigMarta.Media[0].Id])), ct)).Runs.Single();
|
||||
Assert.AreEqual((usb.Id, nas.Id), (luca.DestinationId, marta.DestinationId));
|
||||
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(luca.Id, ct)).State);
|
||||
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(marta.Id, ct)).State);
|
||||
var events = await PauseEventsAsync(bed, ct);
|
||||
|
||||
bed.Clock.Now += TimeSpan.FromMinutes(1);
|
||||
var small = await bed.PostAsync(bed.Luca, "s01", 5);
|
||||
var smallBytes = small.Media[0].Bytes!.Value;
|
||||
Assert.IsGreaterThan(smallBytes, Math.Min(bigLuca.Media[0].Bytes!.Value, bigMarta.Media[0].Bytes!.Value));
|
||||
bed.Disk.Free = ExportSpace.Margin + smallBytes + 10;
|
||||
bed.Clock.Now += TimeSpan.FromHours(1);
|
||||
var worker = Worker(bed);
|
||||
Assert.AreEqual(AutoExportPass.Started, await worker.RunOnceAsync(round: true, ct));
|
||||
await bed.Service.WaitAsync(ct);
|
||||
|
||||
Assert.IsTrue(File.Exists(bed.GeneralCopy(bed.Luca, small.Media[0])), "the new file that fits is copied");
|
||||
Assert.IsNull((await bed.Db.Exports.GetDestinationAsync(usb.Id, ct))!.PausedAt);
|
||||
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(luca.Id, ct)).State, "a manual «In pausa» stays Alberto's");
|
||||
Assert.IsNotNull((await bed.Db.Exports.GetDestinationAsync(nas.Id, ct))!.PausedAt, "his file still does not fit there");
|
||||
Assert.AreEqual(ExportRunState.Paused, (await bed.RunAsync(marta.Id, ct)).State);
|
||||
Assert.AreEqual(events, await PauseEventsAsync(bed, ct));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The start-up round resumes the automatic runs the last stop left «interrotto» (RecoverAsync), never a run of
|
||||
/// Alberto's; and a manual «In pausa» stays paused when the round finds its folder back (answer 48).
|
||||
|
||||
Reference in new issue
Block a user