Files
Chronos/tests/Titano.App.Tests/Uploader/SingleThreadedContext.cs
T
Claude 2a74c12fd1 feat(uploader): upload engine with queue retries and verified-only source deletion
Two parallel files: hash, resumable upload through a transport, then
verified or already-on-server. Failed items retry after 30 s up to 3
times on top of the client's transient retries; an unreachable server
requeues without spending a retry. A new-sequence batch creates its
sequence once. "Delete after upload" removes only files the server
confirmed and that still match the hashed size and write time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 10:27:24 +00:00

42 lines
1.3 KiB
C#

using System.Collections.Concurrent;
namespace Titano.App.Tests.Uploader;
/// <summary>Runs async test code on one thread, as the UI dispatcher does for the upload engine.</summary>
internal sealed class SingleThreadedContext : SynchronizationContext
{
private readonly BlockingCollection<(SendOrPostCallback Callback, object? State)> _queue = [];
public override void Post(SendOrPostCallback d, object? state)
{
try
{
_queue.Add((d, state));
}
catch (InvalidOperationException)
{
// Late progress reports after the test body finished are dropped.
}
}
public override void Send(SendOrPostCallback d, object? state) => throw new NotSupportedException();
public static void Run(Func<Task> body)
{
var previous = Current;
var context = new SingleThreadedContext();
SetSynchronizationContext(context);
try
{
var task = body();
task.ContinueWith(_ => context._queue.CompleteAdding(), TaskScheduler.Default);
foreach (var (callback, state) in context._queue.GetConsumingEnumerable()) callback(state);
task.GetAwaiter().GetResult();
}
finally
{
SetSynchronizationContext(previous);
}
}
}