fix(app): exit without waiting for the UI thread, close the editor with the shell, cancel sign-in safely
DESK-1: SyncHost's dispose, session switch and stop now continue on the thread pool (ConfigureAwait(false)) and keep the running agent in one reference. A signed-in user whose archive is not polled no longer waits 10 s at every exit, after which the job engine and the index were never closed. DESK-7: ShellViewModel.Dispose disposes the Sequence section first, so the open editor stops its runners and closes its source before the engine and the index go. DESK-8: Cancel stays available while the server answers a sign-in. It now cancels the request; an answer that still arrives changes nothing (the connection flow ignores answers for a client it dropped), and a sign-in that completed just before the cancel was handled is signed out again. The form no longer sets a result after it closed, and an unexpected failure shows inline instead of escaping async void. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
8 files changed
+345
-35
No files matched your search
@@ -0,0 +1,61 @@
|
||||
using System.Diagnostics;
|
||||
using Titano.App.DesignTime;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Tests.Uploader;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Server;
|
||||
|
||||
public sealed class SyncHostTests
|
||||
{
|
||||
/// <summary>Dialogs that answer like a user who cancels everything.</summary>
|
||||
private sealed class NoDialogs : IAppDialogs
|
||||
{
|
||||
public string? PickFolder(string title, string? initialFolder = null) => null;
|
||||
public string? PickJsonFile(string title) => null;
|
||||
public bool Confirm(ConfirmRequest request) => false;
|
||||
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DESK-1: a signed-in user whose archive is not polled (no archive, or offline at start) exits. Nothing before the
|
||||
/// sync agent's stop leaves the UI thread, and the agent stops asynchronously: its continuation must not need the UI
|
||||
/// thread that App.OnExit blocks, or the exit waits 10 s and never closes the engine and the index.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void ExitWithASignedInSessionAndNoPollingDoesNotWaitForTheUiThread()
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
try
|
||||
{
|
||||
SingleThreadedContext.Run(async () =>
|
||||
{
|
||||
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
||||
var sample = SampleData.Configure(services);
|
||||
// An index without the archive poller (OpenAsync never ran) and a saved session, as for a server-only user.
|
||||
await sample.OpenEmptyAsync();
|
||||
await sample.FillAsync();
|
||||
services.Settings.RenderNodeOptIn = false;
|
||||
await services.Server.RestoreAsync();
|
||||
Assert.True(services.Server.IsConnected, "session restored");
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(10);
|
||||
while (services.Sync.Agent is null)
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, "sync agent not started");
|
||||
await Task.Delay(20);
|
||||
}
|
||||
|
||||
// App.OnExit blocks the UI thread until the services stop.
|
||||
var clock = Stopwatch.StartNew();
|
||||
Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
|
||||
Assert.Less(clock.Elapsed.TotalSeconds, 5, "the exit waited for the UI thread");
|
||||
Assert.Null(services.Sync.Agent);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
environment.DeleteCaptureData();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user