Adds transfer speeds to status logs.
This commit is contained in:
parent
074f5ebfae
commit
09554da362
@ -51,6 +51,11 @@
|
||||
public BytesPerSecond(long sizeInBytes) : base(sizeInBytes)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString() + "/s";
|
||||
}
|
||||
}
|
||||
|
||||
public static class ByteSizeIntExtensions
|
||||
|
@ -4,8 +4,8 @@ namespace CodexPlugin
|
||||
{
|
||||
public interface ITransferSpeeds
|
||||
{
|
||||
BytesPerSecond GetUploadSpeed();
|
||||
BytesPerSecond GetDownloadSpeed();
|
||||
BytesPerSecond? GetUploadSpeed();
|
||||
BytesPerSecond? GetDownloadSpeed();
|
||||
}
|
||||
|
||||
public class TransferSpeeds : ITransferSpeeds
|
||||
@ -23,14 +23,16 @@ namespace CodexPlugin
|
||||
downloads.Add(Convert(bytes, duration));
|
||||
}
|
||||
|
||||
public BytesPerSecond GetUploadSpeed()
|
||||
public BytesPerSecond? GetUploadSpeed()
|
||||
{
|
||||
return Average(uploads);
|
||||
if (!uploads.Any()) return null;
|
||||
return uploads.Average();
|
||||
}
|
||||
|
||||
public BytesPerSecond GetDownloadSpeed()
|
||||
public BytesPerSecond? GetDownloadSpeed()
|
||||
{
|
||||
return Average(downloads);
|
||||
if (!downloads.Any()) return null;
|
||||
return downloads.Average();
|
||||
}
|
||||
|
||||
private static BytesPerSecond Convert(ByteSize size, TimeSpan duration)
|
||||
@ -40,13 +42,26 @@ namespace CodexPlugin
|
||||
|
||||
return new BytesPerSecond(System.Convert.ToInt64(Math.Round(bytes / seconds)));
|
||||
}
|
||||
}
|
||||
|
||||
private static BytesPerSecond Average(List<BytesPerSecond> list)
|
||||
public static class ListExtensions
|
||||
{
|
||||
public static BytesPerSecond Average(this List<BytesPerSecond> list)
|
||||
{
|
||||
double sum = list.Sum(i => i.SizeInBytes);
|
||||
double num = list.Count;
|
||||
|
||||
return new BytesPerSecond(System.Convert.ToInt64(Math.Round(sum / num)));
|
||||
return new BytesPerSecond(Convert.ToInt64(Math.Round(sum / num)));
|
||||
}
|
||||
|
||||
public static BytesPerSecond? OptionalAverage(this List<BytesPerSecond?>? list)
|
||||
{
|
||||
if (list == null || !list.Any() || !list.Any(i => i != null)) return null;
|
||||
var values = list.Where(i => i != null).Cast<BytesPerSecond>().ToArray();
|
||||
double sum = values.Sum(i => i.SizeInBytes);
|
||||
double num = values.Length;
|
||||
|
||||
return new BytesPerSecond(Convert.ToInt64(Math.Round(sum / num)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,6 +197,11 @@ namespace ContinuousTests
|
||||
if (error.Contains(":")) error = error.Substring(1 + error.LastIndexOf(":"));
|
||||
result.Add("error", error);
|
||||
|
||||
var upload = nodes.Select(n => n.TransferSpeeds.GetUploadSpeed()).ToList()!.OptionalAverage();
|
||||
var download = nodes.Select(n => n.TransferSpeeds.GetDownloadSpeed()).ToList()!.OptionalAverage();
|
||||
if (upload != null) result.Add("avgupload", upload.ToString());
|
||||
if (download != null) result.Add("avgdownload", download.ToString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,13 @@ using Core;
|
||||
using DistTestCore;
|
||||
using DistTestCore.Helpers;
|
||||
using DistTestCore.Logs;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Constraints;
|
||||
|
||||
namespace CodexTests
|
||||
{
|
||||
public class CodexDistTest : DistTest
|
||||
{
|
||||
private readonly List<ICodexNode> onlineCodexNodes = new List<ICodexNode>();
|
||||
private readonly Dictionary<TestLifecycle, List<ICodexNode>> onlineCodexNodes = new Dictionary<TestLifecycle, List<ICodexNode>>();
|
||||
|
||||
public CodexDistTest()
|
||||
{
|
||||
@ -23,12 +22,6 @@ namespace CodexTests
|
||||
ProjectPlugin.Load<MetricsPlugin.MetricsPlugin>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDownCodexFixture()
|
||||
{
|
||||
onlineCodexNodes.Clear();
|
||||
}
|
||||
|
||||
protected override void Initialize(FixtureLog fixtureLog)
|
||||
{
|
||||
var localBuilder = new LocalCodexBuilder(fixtureLog);
|
||||
@ -36,6 +29,16 @@ namespace CodexTests
|
||||
localBuilder.Build();
|
||||
}
|
||||
|
||||
protected override void LifecycleStart(TestLifecycle lifecycle)
|
||||
{
|
||||
onlineCodexNodes.Add(lifecycle, new List<ICodexNode>());
|
||||
}
|
||||
|
||||
protected override void LifecycleStop(TestLifecycle lifecycle)
|
||||
{
|
||||
onlineCodexNodes.Remove(lifecycle);
|
||||
}
|
||||
|
||||
public ICodexNode AddCodex()
|
||||
{
|
||||
return AddCodex(s => { });
|
||||
@ -58,7 +61,7 @@ namespace CodexTests
|
||||
setup(s);
|
||||
OnCodexSetup(s);
|
||||
});
|
||||
onlineCodexNodes.AddRange(group);
|
||||
onlineCodexNodes[Get()].AddRange(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
@ -74,7 +77,7 @@ namespace CodexTests
|
||||
|
||||
public IEnumerable<ICodexNode> GetAllOnlineCodexNodes()
|
||||
{
|
||||
return onlineCodexNodes;
|
||||
return onlineCodexNodes[Get()];
|
||||
}
|
||||
|
||||
public void AssertBalance(ICodexContracts contracts, ICodexNode codexNode, Constraint constraint, string msg = "")
|
||||
@ -85,5 +88,14 @@ namespace CodexTests
|
||||
protected virtual void OnCodexSetup(ICodexSetup setup)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void CollectStatusLogData(TestLifecycle lifecycle, Dictionary<string, string> data)
|
||||
{
|
||||
var nodes = onlineCodexNodes[lifecycle];
|
||||
var upload = nodes.Select(n => n.TransferSpeeds.GetUploadSpeed()).ToList()!.OptionalAverage();
|
||||
var download = nodes.Select(n => n.TransferSpeeds.GetDownloadSpeed()).ToList()!.OptionalAverage();
|
||||
if (upload != null) data.Add("avgupload", upload.ToString());
|
||||
if (download != null) data.Add("avgdownload", download.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +147,18 @@ namespace DistTestCore
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void LifecycleStart(TestLifecycle lifecycle)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void LifecycleStop(TestLifecycle lifecycle)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void CollectStatusLogData(TestLifecycle lifecycle, Dictionary<string, string> data)
|
||||
{
|
||||
}
|
||||
|
||||
protected TestLifecycle Get()
|
||||
{
|
||||
lock (lifecycleLock)
|
||||
@ -166,6 +178,7 @@ namespace DistTestCore
|
||||
var testNamespace = TestNamespacePrefix + Guid.NewGuid().ToString();
|
||||
var lifecycle = new TestLifecycle(fixtureLog.CreateTestLog(), configuration, GetTimeSet(), testNamespace);
|
||||
lifecycles.Add(testName, lifecycle);
|
||||
LifecycleStart(lifecycle);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -175,13 +188,16 @@ namespace DistTestCore
|
||||
var lifecycle = Get();
|
||||
var testResult = GetTestResult();
|
||||
var testDuration = lifecycle.GetTestDuration();
|
||||
var data = lifecycle.GetPluginMetadata();
|
||||
CollectStatusLogData(lifecycle, data);
|
||||
fixtureLog.Log($"{GetCurrentTestName()} = {testResult} ({testDuration})");
|
||||
statusLog.ConcludeTest(testResult, testDuration, lifecycle.GetPluginMetadata());
|
||||
statusLog.ConcludeTest(testResult, testDuration, data);
|
||||
Stopwatch.Measure(fixtureLog, $"Teardown for {GetCurrentTestName()}", () =>
|
||||
{
|
||||
WriteEndTestLog(lifecycle.Log);
|
||||
|
||||
IncludeLogsOnTestFailure(lifecycle);
|
||||
LifecycleStop(lifecycle);
|
||||
lifecycle.DeleteAllResources();
|
||||
lifecycle = null!;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user