2024-04-01 09:00:52 +00:00
|
|
|
|
using CodexPlugin;
|
2023-09-12 13:43:30 +00:00
|
|
|
|
using DistTestCore;
|
2023-09-15 13:52:02 +00:00
|
|
|
|
using GethPlugin;
|
2023-09-13 09:25:08 +00:00
|
|
|
|
using MetricsPlugin;
|
2023-09-12 13:43:30 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Utils;
|
|
|
|
|
|
2023-10-09 14:59:52 +00:00
|
|
|
|
namespace CodexTests.BasicTests
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2023-09-19 14:22:07 +00:00
|
|
|
|
public class ExampleTests : CodexDistTest
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void CodexLogExample()
|
|
|
|
|
{
|
2023-10-07 07:48:12 +00:00
|
|
|
|
var primary = AddCodex(s => s.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Warn, CodexLogLevel.Warn)));
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-11-10 07:20:08 +00:00
|
|
|
|
var cid = primary.UploadFile(GenerateTestFile(5.MB()));
|
|
|
|
|
|
2024-03-26 13:07:06 +00:00
|
|
|
|
var localDatasets = primary.LocalFiles();
|
|
|
|
|
CollectionAssert.Contains(localDatasets.Content.Select(c => c.Cid), cid);
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-09-14 13:26:46 +00:00
|
|
|
|
var log = Ci.DownloadLog(primary);
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
|
|
|
|
log.AssertLogContains("Uploaded file");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TwoMetricsExample()
|
|
|
|
|
{
|
2023-09-19 14:22:07 +00:00
|
|
|
|
var group = AddCodex(2, s => s.EnableMetrics());
|
|
|
|
|
var group2 = AddCodex(2, s => s.EnableMetrics());
|
2023-09-13 09:25:08 +00:00
|
|
|
|
|
2023-09-13 09:59:21 +00:00
|
|
|
|
var primary = group[0];
|
|
|
|
|
var secondary = group[1];
|
|
|
|
|
var primary2 = group2[0];
|
|
|
|
|
var secondary2 = group2[1];
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-09-19 09:51:59 +00:00
|
|
|
|
var metrics = Ci.GetMetricsFor(primary, primary2);
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-09-13 09:59:21 +00:00
|
|
|
|
primary.ConnectToPeer(secondary);
|
|
|
|
|
primary2.ConnectToPeer(secondary2);
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-09-13 09:59:21 +00:00
|
|
|
|
Thread.Sleep(TimeSpan.FromMinutes(2));
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
2023-09-13 09:59:21 +00:00
|
|
|
|
metrics[0].AssertThat("libp2p_peers", Is.EqualTo(1));
|
|
|
|
|
metrics[1].AssertThat("libp2p_peers", Is.EqualTo(1));
|
2023-09-12 13:43:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-21 09:33:11 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void GethBootstrapTest()
|
|
|
|
|
{
|
|
|
|
|
var boot = Ci.StartGethNode(s => s.WithName("boot").IsMiner());
|
|
|
|
|
var disconnected = Ci.StartGethNode(s => s.WithName("disconnected"));
|
|
|
|
|
var follow = Ci.StartGethNode(s => s.WithBootstrapNode(boot).WithName("follow"));
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(12000);
|
|
|
|
|
|
|
|
|
|
var bootN = boot.GetSyncedBlockNumber();
|
|
|
|
|
var discN = disconnected.GetSyncedBlockNumber();
|
|
|
|
|
var followN = follow.GetSyncedBlockNumber();
|
|
|
|
|
|
|
|
|
|
Assert.That(bootN, Is.EqualTo(followN));
|
|
|
|
|
Assert.That(discN, Is.LessThan(bootN));
|
|
|
|
|
}
|
2023-09-12 13:43:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|