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

127 lines
4.0 KiB
C#
Raw Normal View History

2023-08-14 10:26:04 +02:00
using DistTestCore;
2023-08-14 15:10:36 +02:00
using KubernetesWorkflow;
2023-08-02 15:11:27 +02:00
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
{
[TestFixture]
2023-08-14 15:10:36 +02:00
public class ContinuousSubstitute : AutoBootstrapDistTest, ILogHandler
2023-08-02 15:11:27 +02:00
{
[Test]
2023-08-08 14:42:59 +02:00
[UseLongTimeouts]
2023-08-02 15:11:27 +02:00
public void ContinuousTestSubstitute()
{
2023-08-14 10:26:04 +02:00
var group = SetupCodexNodes(5, o => o
.EnableMetrics()
.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true)
.WithBlockTTL(TimeSpan.FromMinutes(2))
.WithStorageQuota(3.GB()));
2023-08-02 15:11:27 +02:00
2023-08-14 10:26:04 +02:00
var nodes = group.Cast<OnlineCodexNode>().ToArray();
2023-08-02 15:11:27 +02:00
2023-08-14 10:26:04 +02:00
foreach (var node in nodes)
2023-08-02 15:11:27 +02:00
{
2023-08-14 10:26:04 +02:00
node.Marketplace.MakeStorageAvailable(
size: 1.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 1024.TestTokens(),
maxDuration: TimeSpan.FromMinutes(5));
}
2023-08-02 15:11:27 +02:00
2023-08-14 10:26:04 +02:00
var endTime = DateTime.UtcNow + TimeSpan.FromHours(10);
while (DateTime.UtcNow < endTime)
{
var allNodes = nodes.ToList();
var primary = allNodes.PickOneRandom();
var secondary = allNodes.PickOneRandom();
2023-08-02 15:11:27 +02:00
2023-08-14 10:26:04 +02:00
Log("Run Test");
PerformTest(primary, secondary);
2023-08-02 15:11:27 +02:00
2023-08-14 10:26:04 +02:00
Thread.Sleep(TimeSpan.FromSeconds(5));
2023-08-02 15:11:27 +02:00
}
}
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);
});
}
2023-08-14 15:10:36 +02:00
2023-08-14 10:26:04 +02:00
[Test]
[UseLongTimeouts]
public void HoldMyBeerTest()
{
var group = SetupCodexNodes(5, o => o
.EnableMetrics()
.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true)
.WithBlockTTL(TimeSpan.FromMinutes(2))
.WithBlockMaintenanceInterval(TimeSpan.FromMinutes(3))
.WithBlockMaintenanceNumber(10000)
2023-08-14 10:26:04 +02:00
.WithStorageQuota(3.GB()));
var nodes = group.Cast<OnlineCodexNode>().ToArray();
2023-08-14 15:10:36 +02:00
var flow = Get().WorkflowCreator.CreateWorkflow();
var cst = new CancellationTokenSource();
var tasks = nodes.Select(n => flow.WatchForCrashLogs(n.CodexAccess.Container, cst.Token, this)).ToArray();
2023-08-14 10:26:04 +02:00
2023-08-14 15:10:36 +02:00
try
2023-08-14 10:26:04 +02:00
{
foreach (var node in nodes)
{
2023-08-14 15:10:36 +02:00
node.Marketplace.MakeStorageAvailable(
size: 1.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 1024.TestTokens(),
maxDuration: TimeSpan.FromMinutes(5));
}
2023-08-14 10:26:04 +02:00
2023-08-14 15:10:36 +02:00
var endTime = DateTime.UtcNow + TimeSpan.FromHours(2);
while (DateTime.UtcNow < endTime)
{
foreach (var node in nodes)
{
var file = GenerateTestFile(80.MB());
var cid = node.UploadFile(file);
var dl = node.DownloadContent(cid);
file.AssertIsEqual(dl);
}
Thread.Sleep(TimeSpan.FromMinutes(2));
2023-08-14 10:26:04 +02:00
}
2023-08-14 15:10:36 +02:00
}
finally
{
cst.Cancel();
foreach (var t in tasks) t.Wait();
}
}
2023-08-14 10:26:04 +02:00
2023-08-14 15:10:36 +02:00
public void Log(Stream log)
{
Log("Well damn, container crashed. Here's the log:");
using var reader = new StreamReader(log);
var line = reader.ReadLine();
while(line != null)
{
Log(line);
line = reader.ReadLine();
2023-08-14 10:26:04 +02:00
}
}
2023-08-02 15:11:27 +02:00
}
}