cs-codex-dist-tests/Tests/BasicTests/ContinuousSubstitute.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2023-08-02 15:11:27 +02:00
using ContinuousTests;
using DistTestCore;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
{
[TestFixture]
public class ContinuousSubstitute : AutoBootstrapDistTest
{
[Test]
2023-08-08 14:42:59 +02:00
[UseLongTimeouts]
2023-08-02 15:11:27 +02:00
public void ContinuousTestSubstitute()
{
var nodes = new List<OnlineCodexNode>();
for (var i = 0; i < 5; i++)
{
nodes.Add((OnlineCodexNode)SetupCodexNode(o => o
.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: i < 2)
2023-08-08 09:44:38 +02:00
.WithStorageQuota(3.GB())
2023-08-02 15:11:27 +02:00
));
}
var cts = new CancellationTokenSource();
var ct = cts.Token;
var dlPath = Path.Combine(new FileInfo(Get().Log.LogFile.FullFilename)!.Directory!.FullName, "continuouslogs");
Directory.CreateDirectory(dlPath);
var containers = nodes.Select(n => n.CodexAccess.Container).ToArray();
var cd = new ContinuousLogDownloader(Get(), containers, dlPath, ct);
var logTask = Task.Run(cd.Run);
try
{
foreach (var node in nodes)
{
node.Marketplace.MakeStorageAvailable(
size: 1.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 1024.TestTokens(),
maxDuration: TimeSpan.FromMinutes(5));
}
var endTime = DateTime.UtcNow + TimeSpan.FromHours(1);
while (DateTime.UtcNow < endTime)
{
var allNodes = nodes.ToList();
var primary = allNodes.PickOneRandom();
var secondary = allNodes.PickOneRandom();
Log("Run Test");
PerformTest(primary, secondary);
2023-08-08 14:42:59 +02:00
Thread.Sleep(TimeSpan.FromSeconds(5));
2023-08-02 15:11:27 +02:00
}
}
finally
{
cts.Cancel();
logTask.Wait();
}
}
2023-08-08 14:42:59 +02:00
private ByteSize fileSize = 80.MB();
2023-08-08 10:45:16 +02:00
2023-08-02 15:11:27 +02:00
private void PerformTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
{
ScopedTestFiles(() =>
{
2023-08-08 10:45:16 +02:00
var testFile = GenerateTestFile(fileSize);
2023-08-02 15:11:27 +02:00
var contentId = primary.UploadFile(testFile);
var downloadedFile = secondary.DownloadContent(contentId);
testFile.AssertIsEqual(downloadedFile);
});
}
}
}