merge: deterministic sync tests and a current-log download that survives new lines
This commit is contained in:
5 files changed
+175
-27
No files matched your search
@@ -1,7 +1,10 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Titano.Protocol;
|
||||
using Titano.Server.Hosting;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Server.Tests.Api;
|
||||
@@ -66,6 +69,45 @@ public sealed class AdminTests(TestContext context)
|
||||
await traversal.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheCurrentLogDownloadsWhileTheServerKeepsLogging()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, o => o.LogLevel = Microsoft.Extensions.Logging.LogLevel.Information);
|
||||
var admin = await server.AdminAsync();
|
||||
using var files = await admin.GetAsync("/api/v1/logs/files");
|
||||
var name = (await files.ReadAsync(ProtocolJson.Default.ListLogFileDto)).First().Name;
|
||||
// Jobs, uploads and sign-ins keep writing to the file an administrator downloads: a log of a few megabytes takes
|
||||
// a while to send, and a line lands about every millisecond meanwhile. Only to the file and never in a tight loop:
|
||||
// engine code of every test server in this process logs through the last one started, so this server's console
|
||||
// and file lock are shared with the tests running alongside.
|
||||
var logger = server.Services.GetServices<ILoggerProvider>().OfType<FileLoggerProvider>().Single().CreateLogger("Titano.Server.Tests");
|
||||
var block = new string('x', 64 * 1024);
|
||||
for (var i = 0; i < 32; i++) logger.LogInformation("{Block}", block);
|
||||
using var stop = new CancellationTokenSource();
|
||||
var logging = Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (!stop.IsCancellationRequested)
|
||||
{
|
||||
logger.LogInformation("Busy");
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
using var download = await admin.GetAsync($"/api/v1/logs/files/{name}");
|
||||
await download.ExpectAsync(HttpStatusCode.OK);
|
||||
Assert.Equal(download.Content.Headers.ContentLength, (await download.Content.ReadAsByteArrayAsync()).LongLength);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
await stop.CancelAsync();
|
||||
await logging;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ArchiveSettingsValidateTemplatesAndJobsNeedHandlers()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user