cs-codex-dist-tests/Tests/CodexTests/BasicTests/OneClientTests.cs

67 lines
1.9 KiB
C#
Raw Normal View History

2023-09-12 13:43:30 +00:00
using CodexPlugin;
using FileUtils;
2023-09-12 13:43:30 +00:00
using NUnit.Framework;
using System.Diagnostics;
2023-09-12 13:43:30 +00:00
using Utils;
namespace CodexTests.BasicTests
2023-09-12 13:43:30 +00:00
{
[TestFixture]
public class OneClientTests : CodexDistTest
2023-09-12 13:43:30 +00:00
{
[Test]
public void OneClientTest()
{
var node = StartCodex();
2023-09-12 13:43:30 +00:00
PerformOneClientTest(node);
2024-06-06 08:31:31 +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)));
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)
{
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);
}
}
}