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]
|
|
|
|
|
public void HoldMyBeerTest()
|
|
|
|
|
{
|
2023-08-15 10:03:01 +02:00
|
|
|
|
var group = SetupCodexNodes(2, o => o
|
2023-08-14 10:26:04 +02:00
|
|
|
|
.EnableMetrics()
|
2023-08-15 10:03:01 +02:00
|
|
|
|
//.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true)
|
2023-08-14 10:26:04 +02:00
|
|
|
|
.WithBlockTTL(TimeSpan.FromMinutes(2))
|
2023-08-15 10:03:01 +02:00
|
|
|
|
.WithBlockMaintenanceInterval(TimeSpan.FromMinutes(10))
|
2023-08-14 16:37:31 +02:00
|
|
|
|
.WithBlockMaintenanceNumber(10000)
|
2023-08-15 10:03:01 +02:00
|
|
|
|
.WithStorageQuota(500.MB()));
|
2023-08-14 10:26:04 +02:00
|
|
|
|
|
|
|
|
|
var nodes = group.Cast<OnlineCodexNode>().ToArray();
|
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
//foreach (var node in nodes)
|
|
|
|
|
//{
|
|
|
|
|
// 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-15 11:01:18 +02:00
|
|
|
|
Thread.Sleep(2000);
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
Log("calling crash...");
|
|
|
|
|
var http = new Http(Get().Log, Get().TimeSet, nodes.First().CodexAccess.Address, baseUrl: "/api/codex/v1", nodes.First().CodexAccess.Container.Name);
|
|
|
|
|
var str = http.HttpGetString("debug/crash");
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
Log("crash called.");
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(60));
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
Log("test done.");
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +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);
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
// var dl = node.DownloadContent(cid);
|
|
|
|
|
// file.AssertIsEqual(dl);
|
|
|
|
|
// }
|
2023-08-15 10:03:01 +02:00
|
|
|
|
|
2023-08-15 11:01:18 +02:00
|
|
|
|
// Thread.Sleep(TimeSpan.FromSeconds(30));
|
|
|
|
|
//}
|
2023-08-14 15:10:36 +02:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|