2024-04-25 08:25:12 +00:00
|
|
|
|
using CodexPlugin;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Utils;
|
|
|
|
|
|
2024-05-07 07:49:00 +00:00
|
|
|
|
namespace CodexTests.UtilityTests
|
2024-04-25 08:25:12 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2024-04-25 08:57:19 +00:00
|
|
|
|
public class LogHelperTests : AutoBootstrapDistTest
|
2024-04-25 08:25:12 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2024-05-07 07:49:00 +00:00
|
|
|
|
[Ignore("Used to find the most common log messages.")]
|
2024-04-25 08:25:12 +00:00
|
|
|
|
public void FindMostCommonLogMessages()
|
|
|
|
|
{
|
2024-05-09 07:32:48 +00:00
|
|
|
|
var uploader = StartCodex(s => s.WithName("uploader").WithLogLevel(CodexLogLevel.Trace));
|
|
|
|
|
var downloader = StartCodex(s => s.WithName("downloader").WithLogLevel(CodexLogLevel.Trace));
|
2024-04-25 08:25:12 +00:00
|
|
|
|
|
2024-04-25 13:04:02 +00:00
|
|
|
|
var cid = uploader.UploadFile(GenerateTestFile(100.MB()));
|
2024-04-25 08:25:12 +00:00
|
|
|
|
|
2024-04-25 08:57:19 +00:00
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
var logStartUtc = DateTime.UtcNow;
|
|
|
|
|
Thread.Sleep(1000);
|
2024-04-25 08:25:12 +00:00
|
|
|
|
|
2024-04-25 08:57:19 +00:00
|
|
|
|
downloader.DownloadContent(cid);
|
|
|
|
|
|
2024-04-25 13:04:02 +00:00
|
|
|
|
var map = GetLogMap(downloader, logStartUtc).OrderByDescending(p => p.Value);
|
|
|
|
|
Log("Downloader - Receive");
|
2024-04-25 08:25:12 +00:00
|
|
|
|
foreach (var entry in map)
|
|
|
|
|
{
|
2024-04-25 13:04:02 +00:00
|
|
|
|
if (entry.Value > 9)
|
|
|
|
|
{
|
|
|
|
|
Log($"'{entry.Key}' = {entry.Value}");
|
|
|
|
|
}
|
2024-04-25 08:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-25 08:57:19 +00:00
|
|
|
|
private Dictionary<string, int> GetLogMap(ICodexNode node, DateTime? startUtc = null)
|
2024-04-25 08:25:12 +00:00
|
|
|
|
{
|
|
|
|
|
var log = Ci.DownloadLog(node);
|
|
|
|
|
var map = new Dictionary<string, int>();
|
|
|
|
|
log.IterateLines(line =>
|
|
|
|
|
{
|
2024-04-27 12:20:31 +00:00
|
|
|
|
var log = CodexLogLine.Parse(line);
|
|
|
|
|
if (log == null) return;
|
2024-04-25 08:57:19 +00:00
|
|
|
|
|
|
|
|
|
if (startUtc.HasValue)
|
|
|
|
|
{
|
2024-04-27 12:20:31 +00:00
|
|
|
|
if (log.TimestampUtc < startUtc) return;
|
2024-04-25 08:57:19 +00:00
|
|
|
|
}
|
2024-05-07 07:49:00 +00:00
|
|
|
|
|
2024-04-27 12:20:31 +00:00
|
|
|
|
if (map.ContainsKey(log.Message)) map[log.Message] += 1;
|
|
|
|
|
else map.Add(log.Message, 1);
|
2024-04-25 08:25:12 +00:00
|
|
|
|
});
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|