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).
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -434,9 +434,12 @@ public sealed class ExportStoreAutomaticTests
|
||||
Assert.HasCount(2, events);
|
||||
}
|
||||
|
||||
/// <summary>D11: the first file still to copy of the oldest paused job of a destination.</summary>
|
||||
/// <summary>
|
||||
/// D11: the next file still to copy of each paused copy job of a destination, oldest first, with its form; only the
|
||||
/// automatic jobs when asked.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public async Task FirstPendingBytesOfAPausedRun()
|
||||
public async Task NextPendingFilesOfThePausedRuns()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
@@ -445,15 +448,30 @@ public sealed class ExportStoreAutomaticTests
|
||||
var a = await FileAsync(bed, bed.Luca, "a", 1, bytes: 111, ct: ct);
|
||||
var b = await FileAsync(bed, bed.Luca, "b", 2, bytes: 222, ct: ct);
|
||||
var c = await FileAsync(bed, bed.Luca, "c", 3, bytes: 333, ct: ct);
|
||||
Assert.IsNull(await bed.Db.Exports.GetFirstPendingBytesAsync(general, ct));
|
||||
var d = await FileAsync(bed, bed.Luca, "d", 4, video: true, bytes: 444, ct: ct);
|
||||
Assert.IsEmpty(await bed.Db.Exports.ListNextPendingFilesAsync(general, automaticOnly: false, ct));
|
||||
|
||||
var running = await RunAsync(bed, general, ExportRunState.Interrupted, ct, (c.Media, ExportItemState.Pending));
|
||||
Assert.IsNull(await bed.Db.Exports.GetFirstPendingBytesAsync(general, ct), "solo un lavoro in pausa");
|
||||
await RunAsync(bed, general, ExportRunState.Paused, ct, (a.Media, ExportItemState.Copied), (b.Media, ExportItemState.Pending), (c.Media, ExportItemState.Pending));
|
||||
await RunAsync(bed, general, ExportRunState.Paused, ct, (a.Media, ExportItemState.Pending));
|
||||
Assert.AreEqual(222L, await bed.Db.Exports.GetFirstPendingBytesAsync(general, ct));
|
||||
Assert.IsNull(await bed.Db.Exports.GetFirstPendingBytesAsync(own, ct));
|
||||
Assert.IsNotNull(running);
|
||||
await RunAsync(bed, general, ExportRunState.Interrupted, ct, (c.Media, ExportItemState.Pending));
|
||||
Assert.IsEmpty(await bed.Db.Exports.ListNextPendingFilesAsync(general, automaticOnly: false, ct), "solo un lavoro in pausa");
|
||||
var manual = await RunAsync(bed, general, ExportRunState.Paused, ct, (a.Media, ExportItemState.Copied), (b.Media, ExportItemState.Pending), (c.Media, ExportItemState.Pending));
|
||||
var automatic = await bed.Db.Exports.CreateRunAsync(
|
||||
new ExportRun { DestinationId = general, Origin = ExportRunOrigin.Automatic, State = ExportRunState.Paused, StartedAt = Make.T0 }, ct);
|
||||
await bed.Db.Exports.AddItemsAsync(
|
||||
[new ExportItem { RunId = automatic.Id, MediaId = d.Media, AccountId = bed.Luca.Id, Variant = ExportVariant.Frame, Format = ExportFormat.Png, FrameAt = TimeSpan.Zero }],
|
||||
ct);
|
||||
|
||||
var all = await bed.Db.Exports.ListNextPendingFilesAsync(general, automaticOnly: false, ct);
|
||||
var items = await bed.Db.Exports.ListItemsAsync(new ExportItemQuery { RunId = manual.Id }, ct);
|
||||
var frame = (await bed.Db.Exports.ListItemsAsync(new ExportItemQuery { RunId = automatic.Id }, ct)).Single();
|
||||
CollectionAssert.AreEqual(
|
||||
new[]
|
||||
{
|
||||
new ExportPendingFile(manual.Id, items.Single(i => i.MediaId == b.Media).Id, ExportVariant.Whole, 222),
|
||||
new ExportPendingFile(automatic.Id, frame.Id, ExportVariant.Frame, 444),
|
||||
},
|
||||
all.ToArray());
|
||||
CollectionAssert.AreEqual(new[] { all[1] }, (await bed.Db.Exports.ListNextPendingFilesAsync(general, automaticOnly: true, ct)).ToArray());
|
||||
Assert.IsEmpty(await bed.Db.Exports.ListNextPendingFilesAsync(own, automaticOnly: false, ct));
|
||||
}
|
||||
|
||||
// The signal ---------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user