2025-01-16 15:13:16 +01:00
|
|
|
|
using CodexClient;
|
2024-11-21 10:46:11 +01:00
|
|
|
|
using CodexTests;
|
2024-10-09 09:11:04 +02:00
|
|
|
|
using FileUtils;
|
2023-09-12 15:43:30 +02:00
|
|
|
|
using NUnit.Framework;
|
2024-10-09 09:11:04 +02:00
|
|
|
|
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 09:11:04 +02:00
|
|
|
|
{
|
2024-10-09 11:37:16 +02:00
|
|
|
|
var nodes = StartCodex(10);
|
|
|
|
|
|
|
|
|
|
|
|
var tasks = nodes.Select(n => Task<bool>.Run(() => RunInterruptUploadTest(n)));
|
2024-10-09 09:11:04 +02:00
|
|
|
|
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 09:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-09 11:37:16 +02:00
|
|
|
|
private bool RunInterruptUploadTest(ICodexNode node)
|
2024-10-09 09:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
|
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();
|
2024-10-09 09:11:04 +02:00
|
|
|
|
return !log.GetLinesContaining("Unhandled exception in async proc, aborting").Any();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Process StartCurlUploadProcess(ICodexNode node, TrackedFile file)
|
|
|
|
|
|
{
|
2025-01-15 16:05:57 +01:00
|
|
|
|
var apiAddress = node.GetApiEndpoint();
|
2024-10-09 09:11:04 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|