2023-09-12 13:43:30 +00:00
|
|
|
|
using CodexPlugin;
|
2024-10-09 07:11:04 +00:00
|
|
|
|
using FileUtils;
|
2023-09-12 13:43:30 +00:00
|
|
|
|
using NUnit.Framework;
|
2024-10-09 07:11:04 +00:00
|
|
|
|
using System.Diagnostics;
|
2023-09-12 13:43:30 +00:00
|
|
|
|
using Utils;
|
|
|
|
|
|
2023-10-09 14:59:52 +00:00
|
|
|
|
namespace CodexTests.BasicTests
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2023-12-12 13:18:26 +00:00
|
|
|
|
public class OneClientTests : CodexDistTest
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void OneClientTest()
|
|
|
|
|
{
|
2024-10-09 07:11:04 +00:00
|
|
|
|
var node = StartCodex();
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2024-10-09 07:11:04 +00:00
|
|
|
|
PerformOneClientTest(node);
|
2024-06-06 08:31:31 +00:00
|
|
|
|
|
2024-10-09 07:11:04 +00:00
|
|
|
|
LogNodeStatus(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void InterruptUploadTest()
|
|
|
|
|
{
|
2024-10-09 09:37:16 +00:00
|
|
|
|
var nodes = StartCodex(10);
|
|
|
|
|
|
|
|
|
|
var tasks = nodes.Select(n => Task<bool>.Run(() => RunInterruptUploadTest(n)));
|
2024-10-09 07:11:04 +00:00
|
|
|
|
Task.WaitAll(tasks.ToArray());
|
|
|
|
|
|
|
|
|
|
Assert.That(tasks.Select(t => t.Result).All(r => r == true));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 09:37:16 +00:00
|
|
|
|
private bool RunInterruptUploadTest(ICodexNode node)
|
2024-10-09 07:11:04 +00:00
|
|
|
|
{
|
|
|
|
|
var file = GenerateTestFile(300.MB());
|
|
|
|
|
|
|
|
|
|
var process = StartCurlUploadProcess(node, file);
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
process.Kill();
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
var log = Ci.DownloadLog(node);
|
|
|
|
|
return !log.GetLinesContaining("Unhandled exception in async proc, aborting").Any();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Process StartCurlUploadProcess(ICodexNode node, TrackedFile file)
|
|
|
|
|
{
|
|
|
|
|
var apiAddress = node.Container.GetAddress(CodexContainerRecipe.ApiPortTag);
|
|
|
|
|
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 13:43:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 09:51:59 +00:00
|
|
|
|
private void PerformOneClientTest(ICodexNode primary)
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
var testFile = GenerateTestFile(1.MB());
|
|
|
|
|
|
|
|
|
|
var contentId = primary.UploadFile(testFile);
|
|
|
|
|
|
|
|
|
|
var downloadedFile = primary.DownloadContent(contentId);
|
|
|
|
|
|
|
|
|
|
testFile.AssertIsEqual(downloadedFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|