70 lines
2.0 KiB
C#
Raw Normal View History

2023-09-20 13:33:58 +02:00
using CodexPlugin;
using FileUtils;
using Logging;
using NUnit.Framework;
2023-09-08 10:21:40 +02:00
using Utils;
namespace ContinuousTests.Tests
{
2023-06-25 10:50:01 +02:00
public class TwoClientTest : ContinuousTest
{
private const string BytesStoredMetric = "codexRepostoreBytesUsed";
2023-06-25 10:50:01 +02:00
public override int RequiredNumberOfNodes => 2;
2023-09-04 09:19:04 +02:00
public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(2);
2023-06-25 10:50:01 +02:00
public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure;
2023-06-25 10:50:01 +02:00
private ContentId? cid;
2023-09-20 13:33:58 +02:00
private TrackedFile file = null!;
private readonly ByteSize size = 80.MB();
2023-06-25 10:50:01 +02:00
[TestMoment(t: Zero)]
public void UploadTestFile()
{
file = FileManager.GenerateFile(size);
LogStoredBytes(Nodes[0]);
LogBytesPerMillisecond(() => cid = Nodes[0].UploadFile(file));
Assert.That(cid, Is.Not.Null);
2023-06-25 10:50:01 +02:00
}
2023-07-03 08:39:11 +02:00
[TestMoment(t: 10)]
2023-06-25 10:50:01 +02:00
public void DownloadTestFile()
{
TrackedFile? dl = null;
LogBytesPerMillisecond(() => dl = Nodes[1].DownloadContent(cid!));
2023-06-25 10:50:01 +02:00
file.AssertIsEqual(dl);
}
private void LogStoredBytes(ICodexNode node)
{
var metrics = CreateMetricsAccess(node);
var metric = metrics.GetMetric(BytesStoredMetric);
if (metric == null)
{
Log.Log($"Unabled to fetch metric '{BytesStoredMetric}' for node '{node.GetName()}'");
return;
}
var bytes = new ByteSize(Convert.ToInt64(metric.Values.Single().Value));
Log.Log($"{node.GetName()}: {bytes}");
}
private void LogBytesPerMillisecond(Action action)
{
var sw = Stopwatch.Begin(Log);
action();
var duration = sw.End();
double totalMs = duration.TotalMilliseconds;
double totalBytes = size.SizeInBytes;
var bytesPerMs = totalBytes / totalMs;
Log.Log($"Bytes per millisecond: {bytesPerMs}");
}
2023-06-25 10:50:01 +02:00
}
}