mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-07-30 18:53:21 +00:00
testing in progress
This commit is contained in:
parent
0784804fa4
commit
c1e3e8be09
@ -32,7 +32,7 @@ namespace CodexClient
|
||||
public IDownloadedLog DownloadLog(string additionalName = "")
|
||||
{
|
||||
var file = log.CreateSubfile(GetName() + additionalName);
|
||||
Log($"Downloading logs for '{GetName()}' to '{file.Filename}'");
|
||||
Log($"Downloading logs to '{file.Filename}'");
|
||||
return processControl.DownloadLog(file);
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ namespace CodexClient
|
||||
|
||||
private void Log(string msg)
|
||||
{
|
||||
log.Log($"{GetName()} {msg}");
|
||||
log.Log($"({GetName()}) {msg}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ namespace CodexPlugin
|
||||
|
||||
private ICodexInstance StartBinary(CodexStartupConfig config)
|
||||
{
|
||||
var name = "codex_" + numberSource.GetNextNumber();
|
||||
var name = GetName(config);
|
||||
var dataDir = Path.Combine(dataParentDir, $"datadir_{numberSource.GetNextNumber()}");
|
||||
var pconfig = new CodexProcessConfig(name, freePortFinder, dataDir);
|
||||
Log(pconfig);
|
||||
@ -93,12 +93,21 @@ namespace CodexPlugin
|
||||
metricsEndpoint: null
|
||||
);
|
||||
|
||||
var pc = new BinaryProcessControl(process, pconfig);
|
||||
var pc = new BinaryProcessControl(pluginTools.GetLog(), process, pconfig);
|
||||
processControlMap.Add(instance, pc);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private string GetName(CodexStartupConfig config)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(config.NameOverride))
|
||||
{
|
||||
return config.NameOverride + "_" + numberSource.GetNextNumber();
|
||||
}
|
||||
return "codex_" + numberSource.GetNextNumber();
|
||||
}
|
||||
|
||||
private void LogSeparator()
|
||||
{
|
||||
Log("----------------------------------------------------------------------------");
|
||||
|
||||
@ -6,19 +6,24 @@ namespace CodexPlugin
|
||||
{
|
||||
public class BinaryProcessControl : IProcessControl
|
||||
{
|
||||
private readonly LogFile logFile;
|
||||
private readonly Process process;
|
||||
private readonly CodexProcessConfig config;
|
||||
private readonly List<string> logLines = new List<string>();
|
||||
private readonly List<string> logBuffer = new List<string>();
|
||||
private readonly object bufferLock = new object();
|
||||
private readonly List<Task> streamTasks = new List<Task>();
|
||||
private bool running;
|
||||
|
||||
public BinaryProcessControl(Process process, CodexProcessConfig config)
|
||||
public BinaryProcessControl(ILog log, Process process, CodexProcessConfig config)
|
||||
{
|
||||
logFile = log.CreateSubfile(config.Name);
|
||||
|
||||
running = true;
|
||||
this.process = process;
|
||||
this.config = config;
|
||||
streamTasks.Add(Task.Run(() => ReadProcessStream(process.StandardOutput)));
|
||||
streamTasks.Add(Task.Run(() => ReadProcessStream(process.StandardError)));
|
||||
streamTasks.Add(Task.Run(() => WriteLog()));
|
||||
}
|
||||
|
||||
private void ReadProcessStream(StreamReader reader)
|
||||
@ -26,7 +31,32 @@ namespace CodexPlugin
|
||||
while (running)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
if (!string.IsNullOrEmpty(line)) logLines.Add(line);
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
{
|
||||
lock (bufferLock)
|
||||
{
|
||||
logBuffer.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteLog()
|
||||
{
|
||||
while (running || logBuffer.Count > 0)
|
||||
{
|
||||
if (logBuffer.Count > 0)
|
||||
{
|
||||
var lines = Array.Empty<string>();
|
||||
lock (bufferLock)
|
||||
{
|
||||
lines = logBuffer.ToArray();
|
||||
logBuffer.Clear();
|
||||
}
|
||||
|
||||
foreach (var l in lines) logFile.WriteRaw(l);
|
||||
}
|
||||
else Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,8 +68,7 @@ namespace CodexPlugin
|
||||
|
||||
public IDownloadedLog DownloadLog(LogFile file)
|
||||
{
|
||||
foreach (var line in logLines) file.WriteRaw(line);
|
||||
return new DownloadedLog(file, config.Name);
|
||||
return new DownloadedLog(logFile, config.Name);
|
||||
}
|
||||
|
||||
public bool HasCrashed()
|
||||
|
||||
@ -14,15 +14,15 @@ namespace ExperimentalTests.DownloadConnectivityTests
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
public void SingleSetTest(
|
||||
[Values(1, 10, 100, 1000)] int fileSizeMb,
|
||||
[Values(10, 100, 1000)] int fileSizeMb,
|
||||
[Values(5, 10, 20, 30)] int numDownloaders
|
||||
)
|
||||
{
|
||||
var file = GenerateTestFile(fileSizeMb.MB());
|
||||
var uploaders = StartCodex(n => n.WithName("uploader"));
|
||||
var uploader = StartCodex(n => n.WithName("uploader"));
|
||||
var downloaders = StartCodex(numDownloaders, n => n.WithName("downloader"));
|
||||
|
||||
var cid = uploaders.UploadFile(file);
|
||||
var cid = uploader.UploadFile(file);
|
||||
|
||||
var downloadTasks = new List<Task>();
|
||||
foreach (var dl in downloaders)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user