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

132 lines
4.1 KiB
C#
Raw Normal View History

2023-03-21 12:20:21 +00:00
using CodexDistTestCore;
using NUnit.Framework;
2023-03-21 12:20:21 +00:00
namespace Tests.BasicTests
{
[TestFixture]
2023-03-21 12:20:21 +00:00
public class SimpleTests : DistTest
{
2023-03-28 08:25:48 +00:00
[Test]
public void DoCommand()
2023-03-28 08:25:48 +00:00
{
var primary = SetupCodexNodes(1).BringOnline()[0];
2023-03-22 13:49:01 +00:00
k8sManager.ExampleOfCMD(primary);
2023-03-28 08:25:48 +00:00
}
[Test]
2023-03-29 08:07:16 +00:00
public void TwoMetricsExample()
{
2023-03-27 12:49:34 +00:00
var group = SetupCodexNodes(2)
.EnableMetrics()
.BringOnline();
var group2 = SetupCodexNodes(2)
2023-03-31 08:00:44 +00:00
.EnableMetrics()
.BringOnline();
2023-03-27 12:49:34 +00:00
var primary = group[0];
var secondary = group[1];
var primary2 = group2[0];
var secondary2 = group2[1];
2023-03-22 13:49:01 +00:00
2023-03-27 12:49:34 +00:00
primary.ConnectToPeer(secondary);
primary2.ConnectToPeer(secondary2);
2023-03-24 13:16:59 +00:00
Thread.Sleep(TimeSpan.FromMinutes(5));
2023-03-24 13:16:59 +00:00
2023-03-31 08:00:44 +00:00
primary.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
primary2.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
}
[Test]
public void MarketplaceExample()
{
var primary = SetupCodexNodes(1)
.WithStorageQuota(10.GB())
.EnableMarketplace(initialBalance: 20)
.BringOnline()[0];
var secondary = SetupCodexNodes(1)
.EnableMarketplace(initialBalance: 1000)
.BringOnline()[0];
primary.ConnectToPeer(secondary);
primary.Marketplace.AdvertiseStorage(10.GB(), pricePerMBPerSecond: 0.01f, collateral: 20);
var testFile = GenerateTestFile(10.MB());
var contentId = secondary.UploadFile(testFile);
secondary.Marketplace.AdvertiseContract(contentId, maxPricePerMBPerSecond: 0.02f, minRequiredCollateral: 10, minRequiredNumberOfDuplicates: 1);
primary.Marketplace.AssertThatBalance(Is.LessThan(20), "Collateral was not placed.");
var primaryBalance = primary.Marketplace.GetBalance();
secondary.Marketplace.AssertThatBalance(Is.LessThan(1000), "Contractor was not charged for storage.");
primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage.");
}
2023-03-28 08:25:48 +00:00
[Test]
public void OneClientTest()
{
var primary = SetupCodexNodes(1).BringOnline()[0];
2023-03-28 08:25:48 +00:00
var testFile = GenerateTestFile(1.MB());
2023-03-22 13:49:01 +00:00
2023-03-28 08:25:48 +00:00
var contentId = primary.UploadFile(testFile);
2023-03-28 08:25:48 +00:00
var downloadedFile = primary.DownloadContent(contentId);
2023-03-28 08:25:48 +00:00
testFile.AssertIsEqual(downloadedFile);
}
2023-03-28 08:25:48 +00:00
[Test]
public void TwoClientsOnePodTest()
{
var group = SetupCodexNodes(2).BringOnline();
2023-03-28 08:25:48 +00:00
var primary = group[0];
var secondary = group[1];
2023-03-28 08:25:48 +00:00
PerformTwoClientTest(primary, secondary);
}
2023-03-28 08:25:48 +00:00
[Test]
public void TwoClientsTwoPodsTest()
{
var primary = SetupCodexNodes(1).BringOnline()[0];
2023-03-28 08:25:48 +00:00
var secondary = SetupCodexNodes(1).BringOnline()[0];
2023-03-28 08:25:48 +00:00
PerformTwoClientTest(primary, secondary);
}
2023-03-27 12:49:34 +00:00
[Test]
2023-03-31 08:37:55 +00:00
[Ignore("Requires Location map to be configured for k8s cluster.")]
public void TwoClientsTwoLocationsTest()
{
var primary = SetupCodexNodes(1)
.At(Location.BensLaptop)
.BringOnline()[0];
2023-03-27 12:49:34 +00:00
var secondary = SetupCodexNodes(1)
.At(Location.BensOldGamingMachine)
.BringOnline()[0];
2023-03-27 12:49:34 +00:00
PerformTwoClientTest(primary, secondary);
}
2023-03-22 13:49:01 +00:00
private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
{
2023-03-22 10:27:51 +00:00
primary.ConnectToPeer(secondary);
2023-03-22 10:27:51 +00:00
var testFile = GenerateTestFile(1.MB());
2023-03-22 10:27:51 +00:00
var contentId = primary.UploadFile(testFile);
2023-03-22 10:27:51 +00:00
var downloadedFile = secondary.DownloadContent(contentId);
testFile.AssertIsEqual(downloadedFile);
}
}
}