XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEWarframe.Client.Runtime;
using Xunit;

namespace XFEWarframe.Client.Tests;

public sealed class AsyncClientLogTests
{
    [Fact] public async Task SlowDiagnosticSinkCannotBlockTheProducerAndHasABoundedQueue()
    {
        var entered = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
        var release = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
        await using var log = new AsyncClientLog(async _ => { entered.TrySetResult(); await release.Task; }, 4);
        Assert.True(log.TryWrite("first")); await entered.Task.WaitAsync(TimeSpan.FromSeconds(5));
        try
        {
            var producer = Task.Run(() => { for (var i = 0; i < 10000; i++) log.TryWrite("queued"); });
            await producer.WaitAsync(TimeSpan.FromSeconds(5));
            Assert.True(log.Dropped >= 9996);
        }
        finally { release.TrySetResult(); }
    }
    [Fact] public async Task DisposeDrainsDiagnosticsInOrder()
    {
        var rows = new List<string>();
        var log = new AsyncClientLog(message => { rows.Add(message); return ValueTask.CompletedTask; }, 128);
        for (var i = 0; i < 100; i++) Assert.True(log.TryWrite(i.ToString()));
        await log.DisposeAsync();
        Assert.Equal(Enumerable.Range(0, 100).Select(i => i.ToString()), rows);
        Assert.False(log.TryWrite("closed"));
    }
    [Fact] public async Task FileFailureIsReportedWithoutEscapingIntoNativeCallbacks()
    {
        var log = new AsyncClientLog(_ => ValueTask.FromException(new IOException("unavailable")));
        Assert.True(log.TryWrite("message")); await log.DisposeAsync();
        Assert.Equal(nameof(IOException), log.Failure);
    }
}