fix: address the owner review 5 review
Setup: a kept 1.0 Uploader no longer fixes the scope and folder, the Remove tooltip promises kept files only with a hashed log, and a single-program setup preselects it. The Uploader always downloads the setup. Sync links move to the server id at every sign-in while folders wait for jobs and open editors; jobs of a pending homes sort still find their projects. A shared library exposes only the shared archive's client-visible jobs and events, render nodes take only client renders, and the share counts as its own while starting. Progress: a new step waits a quarter interval and a trailing timer publishes the last state; the job bar tooltip carries the whole line; Recent maintenance and the Server jobs list pick up jobs that start while they are shown. Refs #64 #65 #66 #67 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
817956e719
commit
f30eb2904a
51 files changed
+895
-122
No files matched your search
@@ -14,6 +14,9 @@ public sealed class JobContextProgressTests(TestContext context)
|
||||
{
|
||||
private static readonly TimeSpan Tick = TimeSpan.FromMilliseconds(10);
|
||||
|
||||
/// <summary>A quarter of the default publish interval: what a new step waits since the last publish.</summary>
|
||||
private static readonly TimeSpan StepWait = TimeSpan.FromMilliseconds(125);
|
||||
|
||||
[Test]
|
||||
public async Task AHundredReportsInASecondGoOutAtMostThreeTimes()
|
||||
{
|
||||
@@ -24,8 +27,46 @@ public sealed class JobContextProgressTests(TestContext context)
|
||||
run.Time.Advance(Tick);
|
||||
}
|
||||
Assert.True(run.Published.Count <= 3, $"{run.Published.Count} publishes");
|
||||
// The first at once, then one per half second.
|
||||
Assert.SequenceEqual([1L, 51L], run.Published.Select(p => p.Done));
|
||||
// The first at once, then one per half second: the latest state when its time comes.
|
||||
Assert.SequenceEqual([1L, 50L, 100L], run.Published.Select(p => p.Done));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AJobGoneQuietInALongStepShowsItsLatestStateOnTime()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
// Maintenance: its first sub-steps take milliseconds, the third runs for minutes without a report.
|
||||
await run.Context.ReportAsync(0, 5, new JobDetail(JobStep.Maintenance, "leases", 0, 0, 1, 5, JobPartUnit.Step));
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(30));
|
||||
await run.Context.CheckpointAsync("leases", 1, 5, new JobDetail(JobStep.Maintenance, "temp", 0, 0, 2, 5, JobPartUnit.Step));
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(30));
|
||||
var packs = new JobDetail(JobStep.Maintenance, "packs", 0, 0, 3, 5, JobPartUnit.Step);
|
||||
await run.Context.CheckpointAsync("temp", 2, 5, packs);
|
||||
Assert.Count(1, run.Published);
|
||||
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(500));
|
||||
Assert.Count(2, run.Published);
|
||||
Assert.Equal((2L, packs), (run.Published[^1].Done, run.Published[^1].Detail));
|
||||
// Nothing new: nothing more goes out.
|
||||
run.Time.Advance(TimeSpan.FromSeconds(10));
|
||||
Assert.Count(2, run.Published);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AJobThatAlternatesStepsGoesOutAFewTimesASecond()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
// An incremental scan: every other folder changed, checked and indexed in turn, 200 reports in a second.
|
||||
for (var i = 0; i < 200; i++)
|
||||
{
|
||||
var step = i % 2 == 0 ? JobStep.Check : JobStep.Index;
|
||||
await run.Context.ReportAsync(i, 10_000, new JobDetail(step, "folder " + i, 0, 0, i + 1, 10_000, JobPartUnit.Folder));
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(5));
|
||||
}
|
||||
Assert.True(run.Published.Count <= 10, $"{run.Published.Count} publishes");
|
||||
// The last report still goes out once its time comes.
|
||||
run.Time.Advance(TimeSpan.FromSeconds(1));
|
||||
Assert.Equal(199L, run.Published[^1].Done);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -36,7 +77,8 @@ public sealed class JobContextProgressTests(TestContext context)
|
||||
await run.Context.ReportAsync(1, 10, new JobDetail(JobStep.List));
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.ReportAsync(2, 10, new JobDetail(JobStep.List));
|
||||
run.Time.Advance(Tick);
|
||||
// A new step goes out once a quarter of the interval has passed, not at every switch.
|
||||
run.Time.Advance(StepWait);
|
||||
await run.Context.ReportAsync(3, 10, index);
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.ReportItemAsync(4, 10, 2, 5);
|
||||
@@ -91,7 +133,7 @@ public sealed class JobContextProgressTests(TestContext context)
|
||||
Assert.Equal(published, run.Published.Count);
|
||||
|
||||
var verify = new JobDetail(JobStep.Verify, "Harbour sunset", 1, 9, 1, 3, JobPartUnit.Sequence);
|
||||
run.Time.Advance(Tick);
|
||||
run.Time.Advance(StepWait);
|
||||
await run.Context.CheckpointAsync("53", 53, 100, verify);
|
||||
stored = await run.StoredAsync();
|
||||
Assert.Equal((53L, "53", verify), (stored.ProgressDone, stored.Checkpoint, stored.Detail));
|
||||
|
||||
@@ -5,16 +5,71 @@ using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Jobs;
|
||||
|
||||
/// <summary>A clock the test moves by hand (BCL <see cref="TimeProvider"/>, no package).</summary>
|
||||
/// <summary>
|
||||
/// A clock the test moves by hand (BCL <see cref="TimeProvider"/>, no package), whose timers fire only when
|
||||
/// <see cref="Advance"/> reaches them, on the test's thread.
|
||||
/// </summary>
|
||||
internal sealed class ManualTime : TimeProvider
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly List<Timer> _timers = [];
|
||||
private long _ticks;
|
||||
|
||||
public override long TimestampFrequency => TimeSpan.TicksPerSecond;
|
||||
|
||||
public override long GetTimestamp() => Interlocked.Read(ref _ticks);
|
||||
|
||||
public void Advance(TimeSpan by) => Interlocked.Add(ref _ticks, by.Ticks);
|
||||
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
var timer = new Timer(this, callback, state);
|
||||
timer.Change(dueTime, period);
|
||||
return timer;
|
||||
}
|
||||
|
||||
/// <summary>Moves the clock on, then fires each one-shot timer due by then.</summary>
|
||||
public void Advance(TimeSpan by)
|
||||
{
|
||||
List<Timer> due;
|
||||
lock (_gate)
|
||||
{
|
||||
var now = Interlocked.Add(ref _ticks, by.Ticks);
|
||||
due = [.. _timers.Where(t => t.Due <= now)];
|
||||
foreach (var timer in due) _timers.Remove(timer);
|
||||
}
|
||||
foreach (var timer in due) timer.Fire();
|
||||
}
|
||||
|
||||
private void Schedule(Timer timer, TimeSpan dueTime)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_timers.Remove(timer);
|
||||
if (dueTime == Timeout.InfiniteTimeSpan) return;
|
||||
timer.Due = Interlocked.Read(ref _ticks) + dueTime.Ticks;
|
||||
_timers.Add(timer);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Timer(ManualTime clock, TimerCallback callback, object? state) : ITimer
|
||||
{
|
||||
public long Due { get; set; }
|
||||
|
||||
public bool Change(TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
clock.Schedule(this, dueTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Fire() => callback(state);
|
||||
|
||||
public void Dispose() => clock.Schedule(this, Timeout.InfiniteTimeSpan);
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
Dispose();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Category("jobs")]
|
||||
|
||||
Reference in new issue
Block a user