fix(app): keep Jobs › Scheduled true to the scheduler
Owner review 2, phase 2 (R10) review findings on the desktop: - Showing the Scheduled tab (and coming back to Jobs on it) reads the actions' availability again, as does a Run now answered unavailable; rows and an open editor follow, so turning proxies on no longer needs a restart. - A delete the index refuses keeps the row: the failed call no longer reads as Deleted (the enum's default), so a live schedule never leaves the page. - SchedulerReady completes false when the index (or the engine) does not open, so the tab shows that the schedules do not run instead of an empty panel. - A read of a schedule's last job that started before a live change or a later read is ignored, so a finished job no longer shows as running. - The editor's Action, Unit and Priority dropdowns follow a language change, keeping what was chosen. - Weekly days in the table read from the UI language's first day, as the editor's toggles do. - Backup tooltips no longer promise daily copies with three kept (their translations are dropped for retranslation); two tooltips now name the real Settings rows (Proxy size; Spazio su disco › Limite della cache). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c137e2c74cddef299b2e4179ef0417fa4977953c)
This commit is contained in:
1 parent
3f0e6357b1
commit
5cb6809fd0
14 files changed
+361
-33
No files matched your search
@@ -121,6 +121,47 @@ public sealed class AppServicesTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 2, R10: when the index does not open, the schedules are known not to run at once, so Jobs › Scheduled
|
||||
/// says so instead of waiting for them with an empty tab.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AnIndexThatDoesNotOpenTellsTheScheduledTabTheSchedulesDoNotRun()
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
try
|
||||
{
|
||||
SingleThreadedContext.Run(async () =>
|
||||
{
|
||||
// "File is not a database", and no staged restore to recover it.
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(environment.DatabasePath)!);
|
||||
await File.WriteAllBytesAsync(environment.DatabasePath, [.. Enumerable.Repeat((byte)0x5A, 8192)]);
|
||||
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
||||
try
|
||||
{
|
||||
await services.OpenAsync(environment.DatabasePath);
|
||||
Assert.NotNull(services.OpenError);
|
||||
var ready = services.SchedulerReady;
|
||||
Assert.Same(ready, await Task.WhenAny(ready, Task.Delay(TimeSpan.FromSeconds(TestTiming.Budget(10)))));
|
||||
Assert.False(await ready, "no schedules without an index");
|
||||
|
||||
using var schedules = new SchedulesViewModel(() => services.Scheduler, () => services.Database, _ => false, (_, _, _) => { }, _ => Task.CompletedTask);
|
||||
await schedules.AttachAsync(services.SchedulerReady);
|
||||
Assert.True(schedules.IsLoaded && schedules.IsUnavailable && !schedules.IsRunning, "the tab shows that the schedules do not run");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
environment.DeleteCaptureData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>BRIEF §6.2: a restore staged in Settings › Advanced recovers an index that no longer opens.</summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Globalization;
|
||||
using Chronos.App.Jobs;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Scheduling;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Jobs › Scheduled in another language (owner review 2, R10). These switch the process-wide UI language, so the class is
|
||||
/// serial: in parallel it would race with the English assertions of the classes running beside it.
|
||||
/// </summary>
|
||||
[Serial]
|
||||
public sealed class ScheduleLanguageTests(TestContext context)
|
||||
{
|
||||
/// <summary>The days of a weekly schedule read in the order of the editor's toggles: from the UI language's first day.</summary>
|
||||
[Test]
|
||||
public void WeeklyDaysFollowTheWeekOfTheUiLanguage()
|
||||
{
|
||||
var weekend = ScheduleRecurrence.WeeklyAt([DayOfWeek.Saturday, DayOfWeek.Sunday], new TimeOnly(3, 0));
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
Assert.Equal(DayOfWeek.Sunday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Sunday), ScheduleText.DayShort(DayOfWeek.Saturday)),
|
||||
ScheduleText.Days(weekend.Days));
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.When.Weekly", ScheduleText.Days(weekend.Days), ScheduleText.Time(new TimeOnly(3, 0))), ScheduleText.When(weekend));
|
||||
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||||
Assert.Equal(DayOfWeek.Monday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Saturday), ScheduleText.DayShort(DayOfWeek.Sunday)),
|
||||
ScheduleText.Days(weekend.Days));
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Monday), ScheduleText.DayShort(DayOfWeek.Thursday)),
|
||||
ScheduleText.Days([DayOfWeek.Thursday, DayOfWeek.Monday]));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The editor's dropdowns say their choices in the new language, and keep what was chosen.</summary>
|
||||
[Test]
|
||||
public async Task TheOpenEditorSaysItsChoicesInTheNewLanguage()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
await using var fx = await ScheduleFixture.CreateAsync(context);
|
||||
using var vm = await fx.ViewModelAsync();
|
||||
vm.NewCommand.Execute(null);
|
||||
var editor = Assert.NotNull(vm.Editor);
|
||||
editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Verify);
|
||||
editor.SelectedUnit = editor.Units.Single(u => u.Value == RecurrenceUnit.Minutes);
|
||||
editor.SelectedPriority = editor.Priorities.Single(p => p.Value == JobPriority.Normal);
|
||||
Assert.Equal(("minutes", "Normal"), (editor.SelectedUnit.Label, editor.SelectedPriority.Label));
|
||||
var actions = editor.ActionOptions;
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||||
|
||||
Assert.SequenceEqual(Enum.GetValues<RecurrenceUnit>().Select(u => Loc.L("Jobs.Editor.Unit." + u)), editor.Units.Select(u => u.Label));
|
||||
Assert.SequenceEqual(["In background", "Normale", "Alta"], editor.Priorities.Select(p => p.Label));
|
||||
Assert.Equal((RecurrenceUnit.Minutes, "minuti"), (editor.SelectedUnit.Value, editor.SelectedUnit.Label));
|
||||
Assert.Equal((JobPriority.Normal, "Normale"), (editor.SelectedPriority.Value, editor.SelectedPriority.Label));
|
||||
Assert.True(editor.Units.Any(u => ReferenceEquals(u, editor.SelectedUnit)) && editor.Priorities.Any(p => ReferenceEquals(p, editor.SelectedPriority)),
|
||||
"the choices are among the new options");
|
||||
|
||||
// The actions are new options too, so their dropdown reads their names again.
|
||||
Assert.False(ReferenceEquals(actions, editor.ActionOptions), "the action list was built again");
|
||||
Assert.Equal(("Scansione archivio", ScheduleActions.Verify), (editor.ActionOptions[0].Label, editor.SelectedAction.Name));
|
||||
Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the action is among the new options");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Chronos.App.Jobs;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Housekeeping;
|
||||
@@ -153,6 +155,97 @@ public sealed class SchedulesViewModelTests
|
||||
Assert.Equal(("Every 10 minutes", false), (scan.WhenText, scan.Schedule.CatchUp));
|
||||
}
|
||||
|
||||
/// <summary>A delete the index refuses (busy, locked) keeps the row: the schedule still runs, so it stays in sight.</summary>
|
||||
[Test]
|
||||
public async Task ADeleteThatFailsKeepsTheRow()
|
||||
{
|
||||
await using var fx = await ScheduleFixture.CreateAsync(_context);
|
||||
var toasts = new List<string>();
|
||||
using var vm = await fx.ViewModelAsync(toasts: toasts);
|
||||
await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Orphans", ScheduleActions.Orphans, new RecurrenceDto("monthly", Time: "05:00", DayOfMonth: 1)), null);
|
||||
var mine = vm.Rows.Single(r => !r.IsSystem);
|
||||
await using (var session = await fx.Db.Database.OpenAsync(_context.Cancellation))
|
||||
{
|
||||
await session.ExecuteScriptAsync("CREATE TRIGGER refuse_delete BEFORE DELETE ON schedules BEGIN SELECT RAISE(ABORT, 'the index is busy'); END;",
|
||||
_context.Cancellation);
|
||||
}
|
||||
|
||||
await vm.DeleteAsync(mine);
|
||||
Assert.SequenceEqual([Loc.L("Jobs.Schedule.Failed")], toasts);
|
||||
Assert.Count(4, vm.Rows);
|
||||
Assert.Contains(mine, vm.Rows);
|
||||
Assert.NotNull(await fx.Db.Schedules.GetAsync(mine.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether this PC runs an action is read again when Jobs › Scheduled is shown: proxies turned on in Settings › Archive
|
||||
/// make the Proxies schedule runnable and the action selectable, without a restart.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ShowingTheTabReadsTheActionsAgain()
|
||||
{
|
||||
await using var fx = await ScheduleFixture.CreateAsync(_context);
|
||||
var archive = await fx.Archives.CreateAsync(Path.Combine(fx.Folder, "archive"), "archive", proxies: new ProxyPolicy { LongEdge = ProxyPolicy.Disabled });
|
||||
fx.Settings.LastArchivePath = archive.RootPath;
|
||||
using var vm = await fx.ViewModelAsync();
|
||||
Assert.Null((await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Proxies", ScheduleActions.Proxies, new RecurrenceDto("daily", Time: "01:00")), null)).Problem);
|
||||
var proxies = vm.Rows.Single(r => !r.IsSystem);
|
||||
Assert.False(vm.IsAvailable(ScheduleActions.Proxies));
|
||||
Assert.False(proxies.RunNowCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled"), proxies.RunNowToolTip);
|
||||
vm.NewCommand.Execute(null);
|
||||
var editor = Assert.NotNull(vm.Editor);
|
||||
Assert.False(editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies).IsAvailable);
|
||||
|
||||
await fx.Archives.UpdateSettingsAsync(archive.Id, a => a with { Proxies = a.Proxies with { LongEdge = 1920 } }, _context.Cancellation);
|
||||
await vm.RefreshActionsAsync();
|
||||
Assert.True(vm.IsAvailable(ScheduleActions.Proxies));
|
||||
Assert.True(proxies.RunNowCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Jobs.Schedule.RunNow"), proxies.RunNowToolTip);
|
||||
Assert.Equal(ScheduleText.ActionToolTip(ScheduleActions.Proxies), proxies.ActionToolTip);
|
||||
// The open editor follows too; what it had chosen stays chosen.
|
||||
var chosen = editor.SelectedAction.Name;
|
||||
Assert.True(editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies).IsAvailable);
|
||||
Assert.Equal(chosen, editor.SelectedAction.Name);
|
||||
Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the choice is one of the new options");
|
||||
editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies);
|
||||
Assert.Equal(ScheduleActions.Proxies, editor.SelectedAction.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The last result follows the newest news of the last job: a read of it that started before a live change (or before
|
||||
/// a later read) does not put back an older state.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AReadOfTheLastJobNeverUndoesANewerChange()
|
||||
{
|
||||
await using var fx = await ScheduleFixture.CreateAsync(_context);
|
||||
using var vm = await fx.ViewModelAsync();
|
||||
var job = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Backup, State = JobState.Running };
|
||||
// A row of its own: the view model reads nothing into it meanwhile.
|
||||
var row = new ScheduleRowViewModel(vm.Rows[1].Schedule with { LastOutcome = ScheduleOutcome.Queued, LastJobId = job.Id }, vm);
|
||||
|
||||
// The job ends while it is read: the engine's Done comes first, the read's Running after it.
|
||||
var read = row.BeginLastJobRead();
|
||||
row.SetLastJob(job with { State = JobState.Done });
|
||||
row.SetLoadedLastJob(job, read);
|
||||
Assert.Equal(("done", StatusKind.Done), (row.LastText, row.LastKind));
|
||||
|
||||
// Two reads: the later one wins, whichever ends first.
|
||||
var first = row.BeginLastJobRead();
|
||||
var second = row.BeginLastJobRead();
|
||||
row.SetLoadedLastJob(job with { State = JobState.Failed }, second);
|
||||
row.SetLoadedLastJob(job, first);
|
||||
Assert.Equal(StatusKind.Failed, row.LastKind);
|
||||
|
||||
// A read of the job of the previous run does not apply once the schedule has run again.
|
||||
var stale = row.BeginLastJobRead();
|
||||
row.Update(row.Schedule with { LastJobId = Guid.CreateVersion7() });
|
||||
row.SetLoadedLastJob(job with { State = JobState.Done }, stale);
|
||||
Assert.Null(row.LastJob);
|
||||
Assert.Equal(("queued", StatusKind.Queued), (row.LastText, row.LastKind));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheEditorChecksEachFieldAndBuildsTheRecurrence()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user