Le prove cadevano a ogni carico della CI, ogni volta prove diverse. Dietro alcune c'erano difetti veri: FebeDatabase lasciava i file aperti dopo DisposeAsync (comandi SQLite non chiusi, pool di lettura chiuso dopo lo scrittore), e il WAL spariva durante lo spostamento della cartella Dati; la scheda dell'account senza statistiche leggeva i file di tutta la libreria; l'arresto di FebeApp non aspettava i lavori aggiunti da un avvio in corso. Chromium ha 120 s per avviarsi e aprire la prima scheda, e il ricollegamento smette appena il processo cambia. Nelle prove i limiti di tempo diventano protezioni contro un blocco: attese per condizione con un aiuto comune, limiti per classe nella prova di scala con il tempo migliore, porta 0 e stderr di Chromium nel browser delle prove, e la prova di «Scollega» di WebView2 controlla che il processo esca davvero. Provato su Windows con tutti i core occupati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
3.1 KiB
C#
116 lines
3.1 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading.Channels;
|
|
using Febe.Web.Connection;
|
|
|
|
namespace Febe.Tests.Server.Support;
|
|
|
|
/// <summary>A remote view without browser: the test writes what goes to the page and reads what comes back.</summary>
|
|
internal sealed class FakeRemoteViewHost : IRemoteViewHost
|
|
{
|
|
private readonly Lock _gate = new();
|
|
private readonly List<FakeRemoteViewConnection> _opened = [];
|
|
|
|
/// <summary>
|
|
/// The views opened so far, copied under the lock the server writes with: the tests read it from their own thread
|
|
/// while the server may be adding to it (#46).
|
|
/// </summary>
|
|
public IReadOnlyList<FakeRemoteViewConnection> Opened
|
|
{
|
|
get
|
|
{
|
|
lock (_gate)
|
|
{
|
|
return [.. _opened];
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Unavailable { get; set; }
|
|
|
|
public Task<IRemoteViewConnection> OpenAsync(CancellationToken ct)
|
|
{
|
|
if (Unavailable)
|
|
{
|
|
throw new RemoteViewUnavailableException("Il browser di prova non c'è.");
|
|
}
|
|
|
|
var connection = new FakeRemoteViewConnection();
|
|
lock (_gate)
|
|
{
|
|
if (_opened.LastOrDefault() is { Disposed: false } previous)
|
|
{
|
|
previous.End(RemoteViewEnd.Replaced);
|
|
}
|
|
|
|
_opened.Add(connection);
|
|
}
|
|
|
|
return Task.FromResult<IRemoteViewConnection>(connection);
|
|
}
|
|
}
|
|
|
|
internal sealed class FakeRemoteViewConnection : IRemoteViewConnection
|
|
{
|
|
private readonly Channel<RemoteViewOutput> _output = Channel.CreateUnbounded<RemoteViewOutput>();
|
|
private volatile bool _disposed;
|
|
private volatile object? _ended;
|
|
|
|
public ConcurrentQueue<object> Inputs { get; } = new();
|
|
|
|
/// <summary>Set by the server's thread, read by the test's: volatile.</summary>
|
|
public bool Disposed
|
|
{
|
|
get => _disposed;
|
|
private set => _disposed = value;
|
|
}
|
|
|
|
public RemoteViewEnd? Ended
|
|
{
|
|
get => (RemoteViewEnd?)_ended;
|
|
private set => _ended = value;
|
|
}
|
|
|
|
|
|
public void Write(RemoteViewOutput output) => _output.Writer.TryWrite(output);
|
|
|
|
public void End(RemoteViewEnd reason)
|
|
{
|
|
Ended = reason;
|
|
_output.Writer.TryComplete();
|
|
}
|
|
|
|
public async IAsyncEnumerable<RemoteViewOutput> ReadAsync([EnumeratorCancellation] CancellationToken ct)
|
|
{
|
|
await foreach (var output in _output.Reader.ReadAllAsync(ct))
|
|
{
|
|
yield return output;
|
|
}
|
|
}
|
|
|
|
public Task MouseAsync(RemoteViewMouse input, CancellationToken ct)
|
|
{
|
|
Inputs.Enqueue(input);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task KeyAsync(RemoteViewKey input, CancellationToken ct)
|
|
{
|
|
Inputs.Enqueue(input);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task NavigateAsync(RemoteViewNavigation action, CancellationToken ct)
|
|
{
|
|
Inputs.Enqueue(action);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
Disposed = true;
|
|
_output.Writer.TryComplete();
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|