Isolating issue with peer tests

This commit is contained in:
benbierens 2023-04-30 10:08:32 +02:00
parent 1da481daa1
commit 4dd02a96e9
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 53 additions and 17 deletions

View File

@ -1,11 +1,15 @@
using KubernetesWorkflow;
using Logging;
namespace DistTestCore.Codex
{
public class CodexAccess
{
public CodexAccess(RunningContainer runningContainer)
private readonly BaseLog log;
public CodexAccess(BaseLog log, RunningContainer runningContainer)
{
this.log = log;
Container = runningContainer;
}
@ -40,7 +44,7 @@ namespace DistTestCore.Codex
{
var ip = Container.Pod.Cluster.IP;
var port = Container.ServicePorts[0].Number;
return new Http(ip, port, baseUrl: "/api/codex/v1");
return new Http(log, ip, port, baseUrl: "/api/codex/v1");
}
public string ConnectToPeer(string peerId, string peerMultiAddress)

View File

@ -64,7 +64,7 @@ namespace DistTestCore
private OnlineCodexNode CreateOnlineCodexNode(RunningContainer c, ICodexNodeFactory factory)
{
var access = new CodexAccess(c);
var access = new CodexAccess(lifecycle.Log, c);
EnsureOnline(access);
return factory.CreateOnlineCodexNode(access, this);
}

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Logging;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Net.Http.Json;
@ -8,12 +9,14 @@ namespace DistTestCore
{
public class Http
{
private readonly BaseLog log;
private readonly string ip;
private readonly int port;
private readonly string baseUrl;
public Http(string ip, int port, string baseUrl)
public Http(BaseLog log, string ip, int port, string baseUrl)
{
this.log = log;
this.ip = ip;
this.port = port;
this.baseUrl = baseUrl;
@ -28,8 +31,11 @@ namespace DistTestCore
{
using var client = GetClient();
var url = GetUrl() + route;
Log(url, "");
var result = Time.Wait(client.GetAsync(url));
return Time.Wait(result.Content.ReadAsStringAsync());
var str = Time.Wait(result.Content.ReadAsStringAsync());
Log(url, str);
return str; ;
});
}
@ -52,8 +58,11 @@ namespace DistTestCore
using var client = GetClient();
var url = GetUrl() + route;
using var content = JsonContent.Create(body);
Log(url, JsonConvert.SerializeObject(body));
var result = Time.Wait(client.PostAsync(url, content));
return Time.Wait(result.Content.ReadAsStringAsync());
var str= Time.Wait(result.Content.ReadAsStringAsync());
Log(url, str);
return str;
});
}
@ -63,12 +72,13 @@ namespace DistTestCore
{
using var client = GetClient();
var url = GetUrl() + route;
Log(url, "~ STREAM ~");
var content = new StreamContent(stream);
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
var response = Time.Wait(client.PostAsync(url, content));
return Time.Wait(response.Content.ReadAsStringAsync());
var str =Time.Wait(response.Content.ReadAsStringAsync());
Log(url, str);
return str;
});
}
@ -78,7 +88,7 @@ namespace DistTestCore
{
var client = GetClient();
var url = GetUrl() + route;
Log(url, "~ STREAM ~");
return Time.Wait(client.GetStreamAsync(url));
});
}
@ -88,6 +98,11 @@ namespace DistTestCore
return $"http://{ip}:{port}{baseUrl}";
}
private void Log(string url, string message)
{
log.Debug($"({url}) = '{message}'", 3);
}
private static T Retry<T>(Func<T> operation)
{
var retryCounter = 0;

View File

@ -28,7 +28,7 @@ namespace DistTestCore.Metrics
public IMetricsAccess CreateMetricsAccess(RunningContainer codexContainer)
{
var query = new MetricsQuery(prometheusContainer);
var query = new MetricsQuery(lifecycle.Log, prometheusContainer);
return new MetricsAccess(lifecycle.Log, query, codexContainer);
}
}

View File

@ -1,5 +1,6 @@
using DistTestCore.Codex;
using KubernetesWorkflow;
using Logging;
using System.Globalization;
namespace DistTestCore.Metrics
@ -8,11 +9,12 @@ namespace DistTestCore.Metrics
{
private readonly Http http;
public MetricsQuery(RunningContainers runningContainers)
public MetricsQuery(BaseLog log, RunningContainers runningContainers)
{
RunningContainers = runningContainers;
http = new Http(
log,
runningContainers.RunningPod.Cluster.IP,
runningContainers.Containers[0].ServicePorts[0].Number,
"api/v1");

View File

@ -13,6 +13,14 @@ namespace Tests.BasicTests
var primary = SetupCodexNode();
var secondary = SetupCodexNode(s => s.WithBootstrapNode(primary));
primary.ConnectToPeer(secondary); // This is required for the switchPeers to show up.
// This is required for the enginePeers to show up.
//var file = GenerateTestFile(10.MB());
//var contentId = primary.UploadFile(file);
//var file2 = secondary.DownloadContent(contentId);
//file.AssertIsEqual(file2);
AssertKnowEachother(primary, secondary);
}
@ -24,6 +32,13 @@ namespace Tests.BasicTests
var bootstrap = SetupCodexNode();
var nodes = SetupCodexNodes(number, s => s.WithBootstrapNode(bootstrap));
var file = GenerateTestFile(10.MB());
var contentId = nodes.First().UploadFile(file);
var file2 = nodes.Last().DownloadContent(contentId);
file.AssertIsEqual(file2);
foreach (var node in nodes) bootstrap.ConnectToPeer(node);
foreach (var node in nodes) AssertKnowEachother(node, bootstrap);
for (var x = 0; x < number; x++)
@ -48,13 +63,13 @@ namespace Tests.BasicTests
private void AssertKnows(CodexDebugResponse a, CodexDebugResponse b)
{
var enginePeers = string.Join(",", a.enginePeers.Select(p => p.peerId));
//var enginePeers = string.Join(",", a.enginePeers.Select(p => p.peerId));
var switchPeers = string.Join(",", a.switchPeers.Select(p => p.peerId));
Log.Debug($"Looking for {b.id} in engine-peers [{enginePeers}]");
Log.Debug($"Looking for {b.id} in switch-peers [{switchPeers}]");
//Log.Debug($"Looking for {b.id} in engine-peers [{enginePeers}]");
Log.Debug($"{a.id} is looking for {b.id} in switch-peers [{switchPeers}]");
Assert.That(a.enginePeers.Any(p => p.peerId == b.id), $"Expected peerId '{b.id}' not found in engine-peers [{enginePeers}]");
//Assert.That(a.enginePeers.Any(p => p.peerId == b.id), $"Expected peerId '{b.id}' not found in engine-peers [{enginePeers}]");
Assert.That(a.switchPeers.Any(p => p.peerId == b.id), $"Expected peerId '{b.id}' not found in switch-peers [{switchPeers}]");
}
}