48 lines
1.4 KiB
C#
Raw Normal View History

2025-01-16 15:13:16 +01:00
using CodexClient;
2024-11-21 10:46:11 +01:00
using CodexTests;
using FileUtils;
2023-09-12 15:43:30 +02:00
using NUnit.Framework;
using System.Diagnostics;
2023-09-12 15:43:30 +02:00
using Utils;
2024-11-21 10:46:11 +01:00
namespace CodexReleaseTests.DataTests
2023-09-12 15:43:30 +02:00
{
2024-11-21 10:46:11 +01:00
public class InterruptUploadTest : CodexDistTest
2023-09-12 15:43:30 +02:00
{
[Test]
2024-11-21 10:46:11 +01:00
public void UploadInterruptTest()
{
2024-10-09 11:37:16 +02:00
var nodes = StartCodex(10);
var tasks = nodes.Select(n => Task<bool>.Run(() => RunInterruptUploadTest(n)));
Task.WaitAll(tasks.ToArray());
Assert.That(tasks.Select(t => t.Result).All(r => r == true));
2024-11-21 10:46:11 +01:00
WaitAndCheckNodesStaysAlive(TimeSpan.FromMinutes(2), nodes);
}
2024-10-09 11:37:16 +02:00
private bool RunInterruptUploadTest(ICodexNode node)
{
var file = GenerateTestFile(300.MB());
var process = StartCurlUploadProcess(node, file);
Thread.Sleep(500);
process.Kill();
Thread.Sleep(1000);
2025-01-16 10:15:02 +01:00
var log = node.DownloadLog();
return !log.GetLinesContaining("Unhandled exception in async proc, aborting").Any();
}
private Process StartCurlUploadProcess(ICodexNode node, TrackedFile file)
{
var apiAddress = node.GetApiEndpoint();
var codexUrl = $"{apiAddress}/api/codex/v1/data";
var filePath = file.Filename;
return Process.Start("curl", $"-X POST {codexUrl} -H \"Content-Type: application/octet-stream\" -T {filePath}");
2023-09-12 15:43:30 +02:00
}
}
}