CI / Build and test (push) Successful in 9m58s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 14m8s
CI / PostgreSQL 16 integration (push) Successful in 8m55s
CI / PostgreSQL 17 integration (push) Successful in 8m50s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m22s
A Chronos Server keeps its sequences' projects, as a PC's archive does: Main and named projects with versions under /api/v1/sequences/{id}/projects, the projects capability and the projectChanged event. The desktop opens a server's sequences in the workspace (proxies downloaded, hash-checked, resumable) with Save version, Sync, conflicts, History, Restore and the project actions against the server. Renders can be of a project version. The admin panel lists a sequence's projects and versions. Strings in all 38 languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
128 lines
6.0 KiB
C#
128 lines
6.0 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Diagnostics;
|
|
using Chronos.App.DesignTime;
|
|
using Chronos.App.Infrastructure;
|
|
using Chronos.App.Tests.Uploader;
|
|
using Chronos.Data.Projects;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Phase 5b glue: a server that keeps projects is the home of its sequences' workspace projects while signed in to it,
|
|
/// never another server's; each session start and stop is told as "changes may have been missed", so the workspace
|
|
/// reads its projects' state again (offline once signed out, reachable once signed in anew).
|
|
/// </summary>
|
|
[Test]
|
|
[WindowsOnly]
|
|
public void TheSignedInServerIsTheHomeOfItsProjectsAndEverySessionChangeIsTold()
|
|
{
|
|
var environment = AppEnvironment.ForCapture();
|
|
try
|
|
{
|
|
SingleThreadedContext.Run(async () =>
|
|
{
|
|
await using var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
|
var sample = SampleData.Configure(services);
|
|
sample.Capabilities = [ServerCapabilities.Projects];
|
|
await sample.OpenEmptyAsync();
|
|
await sample.FillAsync();
|
|
services.Settings.RenderNodeOptIn = false;
|
|
var told = new ConcurrentQueue<(string Server, ProjectChangedEvent? Change)>();
|
|
services.Sync.ProjectChanged += (server, change) => told.Enqueue((server, change));
|
|
var sequence = Guid.CreateVersion7();
|
|
|
|
await services.Server.RestoreAsync();
|
|
await UntilAsync(() => services.Sync.Agent is not null && !told.IsEmpty, "session started and told");
|
|
var server = Assert.NotNull(services.Sync.Server);
|
|
Assert.True(services.Sync.HasProjects, "the server keeps projects");
|
|
var home = Assert.NotNull(services.Sync.ServerHome(sequence));
|
|
var reached = (ServerProjectHome)Assert.NotNull(services.Sync.ProjectHome(home));
|
|
Assert.Equal(sequence, reached.SequenceId);
|
|
Assert.Null(services.Sync.ProjectHome(home with { Server = "https://other.example:8443" }));
|
|
Assert.Same(reached.Client, ((ServerProjectHome)services.Sync.ProjectHome(home)!).Client);
|
|
|
|
// Signed out: told again, and its projects have no home to reach (offline) until signed in anew.
|
|
var before = told.Count;
|
|
services.Server.Disconnect();
|
|
await UntilAsync(() => told.Count > before && services.Sync.Agent is null, "session stop told");
|
|
Assert.Null(services.Sync.ProjectHome(home));
|
|
Assert.False(services.Sync.HasProjects);
|
|
before = told.Count;
|
|
await services.Server.RestoreAsync();
|
|
await UntilAsync(() => told.Count > before && services.Sync.Agent is not null, "new session told");
|
|
Assert.NotNull(services.Sync.ProjectHome(home));
|
|
Assert.True(told.All(t => t.Server == server && t.Change is null), "only session changes were told");
|
|
});
|
|
}
|
|
finally
|
|
{
|
|
environment.DeleteCaptureData();
|
|
}
|
|
}
|
|
|
|
private static async Task UntilAsync(Func<bool> condition, string what)
|
|
{
|
|
var until = DateTime.UtcNow + TimeSpan.FromSeconds(TestTiming.Budget(10));
|
|
while (!condition())
|
|
{
|
|
Assert.True(DateTime.UtcNow < until, what);
|
|
await Task.Delay(20);
|
|
}
|
|
}
|
|
}
|