this works!
This commit is contained in:
parent
3d1ee8ebdb
commit
99e5b4c89a
|
@ -18,6 +18,7 @@ namespace CodexDistTestCore.Config
|
|||
{
|
||||
if (config != null) return config;
|
||||
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigFile);
|
||||
//config = KubernetesClientConfiguration.BuildDefaultConfig();
|
||||
return config;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace CodexDistTestCore
|
|||
return;
|
||||
}
|
||||
|
||||
Utils.Sleep(TimeSpan.FromSeconds(10));
|
||||
Utils.Sleep(TimeSpan.FromSeconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace CodexDistTestCore
|
|||
{
|
||||
public interface IMetricsAccess
|
||||
{
|
||||
int GetMostRecentInt(string metricName, IOnlineCodexNode node);
|
||||
int? GetMostRecentInt(string metricName, IOnlineCodexNode node);
|
||||
}
|
||||
|
||||
public class MetricsAccess : IMetricsAccess
|
||||
|
@ -20,38 +20,43 @@ namespace CodexDistTestCore
|
|||
"api/v1");
|
||||
}
|
||||
|
||||
public int GetMostRecentInt(string metricName, IOnlineCodexNode node)
|
||||
public int? GetMostRecentInt(string metricName, IOnlineCodexNode node)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
var off = new DateTimeOffset(now);
|
||||
var nowUnix = off.ToUnixTimeSeconds();
|
||||
var n = (OnlineCodexNode)node;
|
||||
var pod = n.Group.PodInfo!;
|
||||
|
||||
var hour = now.AddHours(-1);
|
||||
var off2 = new DateTimeOffset(hour);
|
||||
var hourUnix = off2.ToUnixTimeSeconds();
|
||||
var response = http.HttpGetJson<PrometheusQueryResponse>($"query?query=last_over_time({metricName}[12h])");
|
||||
if (response.status != "success") return null;
|
||||
|
||||
var response = http.HttpGetJson<PrometheusQueryRangeResponse>($"query_range?query=libp2p_peers&start={hourUnix}&end={nowUnix}&step=100");
|
||||
var forNode = response.data.result.SingleOrDefault(d => d.metric.instance == $"{pod.Ip}:{n.Container.MetricsPort}");
|
||||
if (forNode == null) return null;
|
||||
|
||||
return 0;
|
||||
if (forNode.value == null || forNode.value.Length == 0) return null;
|
||||
|
||||
if (forNode.value.Length != 2) throw new InvalidOperationException("Expected value to be [double, string].");
|
||||
// [0] = double, timestamp
|
||||
// [1] = string, value
|
||||
|
||||
return Convert.ToInt32(forNode.value[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public class PrometheusQueryRangeResponse
|
||||
public class PrometheusQueryResponse
|
||||
{
|
||||
public string status { get; set; } = string.Empty;
|
||||
public PrometheusQueryRangeResponseData data { get; set; } = new();
|
||||
public PrometheusQueryResponseData data { get; set; } = new();
|
||||
}
|
||||
|
||||
public class PrometheusQueryRangeResponseData
|
||||
public class PrometheusQueryResponseData
|
||||
{
|
||||
public string resultType { get; set; } = string.Empty;
|
||||
public PrometheusQueryRangeResponseDataResultEntry[] result { get; set; } = Array.Empty<PrometheusQueryRangeResponseDataResultEntry>();
|
||||
public PrometheusQueryResponseDataResultEntry[] result { get; set; } = Array.Empty<PrometheusQueryResponseDataResultEntry>();
|
||||
}
|
||||
|
||||
public class PrometheusQueryRangeResponseDataResultEntry
|
||||
public class PrometheusQueryResponseDataResultEntry
|
||||
{
|
||||
public ResultEntryMetric metric { get; set; } = new();
|
||||
public ResultEntryValue[] values { get; set; } = Array.Empty<ResultEntryValue>();
|
||||
public object[] value { get; set; } = Array.Empty<object>();
|
||||
}
|
||||
|
||||
public class ResultEntryMetric
|
||||
|
@ -60,9 +65,4 @@ namespace CodexDistTestCore
|
|||
public string instance { get; set; } = string.Empty;
|
||||
public string job { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ResultEntryValue
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,28 +7,28 @@ namespace Tests.BasicTests
|
|||
[TestFixture]
|
||||
public class SimpleTests : DistTest
|
||||
{
|
||||
//[Test]
|
||||
//public void GetDebugInfo()
|
||||
//{
|
||||
// var dockerImage = new CodexDockerImage();
|
||||
[Test]
|
||||
public void GetDebugInfo()
|
||||
{
|
||||
var dockerImage = new CodexDockerImage();
|
||||
|
||||
// var node = SetupCodexNodes(1).BringOnline()[0];
|
||||
var node = SetupCodexNodes(1).BringOnline()[0];
|
||||
|
||||
// var debugInfo = node.GetDebugInfo();
|
||||
var debugInfo = node.GetDebugInfo();
|
||||
|
||||
// Assert.That(debugInfo.spr, Is.Not.Empty);
|
||||
// Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
|
||||
//}
|
||||
Assert.That(debugInfo.spr, Is.Not.Empty);
|
||||
Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
|
||||
}
|
||||
|
||||
//[Test, DontDownloadLogsAndMetricsOnFailure]
|
||||
//public void CanAccessLogs()
|
||||
//{
|
||||
// var node = SetupCodexNodes(1).BringOnline()[0];
|
||||
[Test, DontDownloadLogsAndMetricsOnFailure]
|
||||
public void CanAccessLogs()
|
||||
{
|
||||
var node = SetupCodexNodes(1).BringOnline()[0];
|
||||
|
||||
// var log = node.DownloadLog();
|
||||
var log = node.DownloadLog();
|
||||
|
||||
// log.AssertLogContains("Started codex node");
|
||||
//}
|
||||
log.AssertLogContains("Started codex node");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MetricsExample()
|
||||
|
@ -49,54 +49,54 @@ namespace Tests.BasicTests
|
|||
"Number of peers metric was incorrect.");
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public void OneClientTest()
|
||||
//{
|
||||
// var primary = SetupCodexNodes(1).BringOnline()[0];
|
||||
[Test]
|
||||
public void OneClientTest()
|
||||
{
|
||||
var primary = SetupCodexNodes(1).BringOnline()[0];
|
||||
|
||||
// var testFile = GenerateTestFile(1.MB());
|
||||
var testFile = GenerateTestFile(1.MB());
|
||||
|
||||
// var contentId = primary.UploadFile(testFile);
|
||||
var contentId = primary.UploadFile(testFile);
|
||||
|
||||
// var downloadedFile = primary.DownloadContent(contentId);
|
||||
var downloadedFile = primary.DownloadContent(contentId);
|
||||
|
||||
// testFile.AssertIsEqual(downloadedFile);
|
||||
//}
|
||||
testFile.AssertIsEqual(downloadedFile);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public void TwoClientsOnePodTest()
|
||||
//{
|
||||
// var group = SetupCodexNodes(2).BringOnline();
|
||||
[Test]
|
||||
public void TwoClientsOnePodTest()
|
||||
{
|
||||
var group = SetupCodexNodes(2).BringOnline();
|
||||
|
||||
// var primary = group[0];
|
||||
// var secondary = group[1];
|
||||
var primary = group[0];
|
||||
var secondary = group[1];
|
||||
|
||||
// PerformTwoClientTest(primary, secondary);
|
||||
//}
|
||||
PerformTwoClientTest(primary, secondary);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public void TwoClientsTwoPodsTest()
|
||||
//{
|
||||
// var primary = SetupCodexNodes(1).BringOnline()[0];
|
||||
[Test]
|
||||
public void TwoClientsTwoPodsTest()
|
||||
{
|
||||
var primary = SetupCodexNodes(1).BringOnline()[0];
|
||||
|
||||
// var secondary = SetupCodexNodes(1).BringOnline()[0];
|
||||
var secondary = SetupCodexNodes(1).BringOnline()[0];
|
||||
|
||||
// PerformTwoClientTest(primary, secondary);
|
||||
//}
|
||||
PerformTwoClientTest(primary, secondary);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public void TwoClientsTwoLocationsTest()
|
||||
//{
|
||||
// var primary = SetupCodexNodes(1)
|
||||
// .At(Location.BensLaptop)
|
||||
// .BringOnline()[0];
|
||||
[Test]
|
||||
public void TwoClientsTwoLocationsTest()
|
||||
{
|
||||
var primary = SetupCodexNodes(1)
|
||||
.At(Location.BensLaptop)
|
||||
.BringOnline()[0];
|
||||
|
||||
// var secondary = SetupCodexNodes(1)
|
||||
// .At(Location.BensOldGamingMachine)
|
||||
// .BringOnline()[0];
|
||||
var secondary = SetupCodexNodes(1)
|
||||
.At(Location.BensOldGamingMachine)
|
||||
.BringOnline()[0];
|
||||
|
||||
// PerformTwoClientTest(primary, secondary);
|
||||
//}
|
||||
PerformTwoClientTest(primary, secondary);
|
||||
}
|
||||
|
||||
private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue