2023-09-20 13:33:58 +02:00
|
|
|
|
using CodexPlugin;
|
2023-09-11 10:43:27 +02:00
|
|
|
|
using FileUtils;
|
2023-09-26 15:17:35 +02:00
|
|
|
|
using Logging;
|
2023-06-21 09:27:59 +02:00
|
|
|
|
using NUnit.Framework;
|
2023-09-08 10:21:40 +02:00
|
|
|
|
using Utils;
|
2023-06-21 09:27:59 +02:00
|
|
|
|
|
|
|
|
|
|
namespace ContinuousTests.Tests
|
|
|
|
|
|
{
|
2023-06-25 10:50:01 +02:00
|
|
|
|
public class TwoClientTest : ContinuousTest
|
|
|
|
|
|
{
|
2023-09-26 14:32:28 +02:00
|
|
|
|
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-21 09:27:59 +02:00
|
|
|
|
|
2023-06-25 10:50:01 +02:00
|
|
|
|
private ContentId? cid;
|
2023-09-20 13:33:58 +02:00
|
|
|
|
private TrackedFile file = null!;
|
2023-09-26 15:17:35 +02:00
|
|
|
|
private readonly ByteSize size = 80.MB();
|
2023-06-21 09:27:59 +02:00
|
|
|
|
|
2023-06-25 10:50:01 +02:00
|
|
|
|
[TestMoment(t: Zero)]
|
|
|
|
|
|
public void UploadTestFile()
|
|
|
|
|
|
{
|
2023-09-26 14:32:28 +02:00
|
|
|
|
file = FileManager.GenerateFile(size);
|
2023-06-21 09:27:59 +02:00
|
|
|
|
|
2023-09-27 11:33:54 +02:00
|
|
|
|
LogStoredBytes(Nodes[0]);
|
|
|
|
|
|
|
|
|
|
|
|
LogBytesPerMillisecond(() => cid = Nodes[0].UploadFile(file));
|
|
|
|
|
|
Assert.That(cid, Is.Not.Null);
|
2023-06-25 10:50:01 +02:00
|
|
|
|
}
|
2023-06-21 09:27:59 +02:00
|
|
|
|
|
2023-07-03 08:39:11 +02:00
|
|
|
|
[TestMoment(t: 10)]
|
2023-06-25 10:50:01 +02:00
|
|
|
|
public void DownloadTestFile()
|
|
|
|
|
|
{
|
2023-09-26 15:17:35 +02:00
|
|
|
|
TrackedFile? dl = null;
|
|
|
|
|
|
|
|
|
|
|
|
LogBytesPerMillisecond(() => dl = Nodes[1].DownloadContent(cid!));
|
2023-06-25 10:50:01 +02:00
|
|
|
|
|
|
|
|
|
|
file.AssertIsEqual(dl);
|
|
|
|
|
|
}
|
2023-09-26 14:32:28 +02:00
|
|
|
|
|
2023-09-27 11:33:54 +02:00
|
|
|
|
private void LogStoredBytes(ICodexNode node)
|
2023-09-26 14:32:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
var metrics = CreateMetricsAccess(node);
|
2023-09-27 11:33:54 +02:00
|
|
|
|
var metric = metrics.GetMetric(BytesStoredMetric);
|
|
|
|
|
|
if (metric == null)
|
2023-09-26 14:32:28 +02:00
|
|
|
|
{
|
2023-09-27 11:33:54 +02:00
|
|
|
|
Log.Log($"Unabled to fetch metric '{BytesStoredMetric}' for node '{node.GetName()}'");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var bytes = new ByteSize(Convert.ToInt64(metric.Values.Single().Value));
|
2023-09-26 14:32:28 +02:00
|
|
|
|
|
2023-09-27 11:33:54 +02:00
|
|
|
|
Log.Log($"{node.GetName()}: {bytes}");
|
2023-09-26 14:32:28 +02:00
|
|
|
|
}
|
2023-09-26 15:17:35 +02:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2023-06-21 09:27:59 +02:00
|
|
|
|
}
|