wip
This commit is contained in:
parent
cc3eddf02d
commit
32e7028029
@ -7,6 +7,7 @@ using DiscordRewards;
|
|||||||
using DistTestCore;
|
using DistTestCore;
|
||||||
using GethPlugin;
|
using GethPlugin;
|
||||||
using KubernetesWorkflow.Types;
|
using KubernetesWorkflow.Types;
|
||||||
|
using Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Utils;
|
using Utils;
|
||||||
@ -38,25 +39,37 @@ namespace CodexTests.UtilityTests
|
|||||||
StartHosts(geth, contracts);
|
StartHosts(geth, contracts);
|
||||||
var client = StartClient(geth, contracts);
|
var client = StartClient(geth, contracts);
|
||||||
|
|
||||||
var events = ChainEvents.FromTimeRange(contracts, GetTestRunTimeRange());
|
//var chainState = new ChainState(GetTestLog(), contracts, new DoNothingChainEventHandler(), GetTestRunTimeRange().From);
|
||||||
var chainState = new ChainState(GetTestLog(), contracts, new DoNothingChainEventHandler(), GetTestRunTimeRange().From);
|
|
||||||
|
|
||||||
var apiCalls = new RewardApiCalls(Ci, botContainer);
|
//var running = true;
|
||||||
|
//var task = Task.Run(() =>
|
||||||
|
//{
|
||||||
|
// while (running)
|
||||||
|
// {
|
||||||
|
// Thread.Sleep(TimeSpan.FromMinutes(1));
|
||||||
|
// chainState.Update();
|
||||||
|
// }
|
||||||
|
//});
|
||||||
|
|
||||||
|
var apiCalls = new RewardApiCalls(GetTestLog(), Ci, botContainer);
|
||||||
apiCalls.Start(OnCommand);
|
apiCalls.Start(OnCommand);
|
||||||
|
|
||||||
var purchaseContract = ClientPurchasesStorage(client);
|
var purchaseContract = ClientPurchasesStorage(client);
|
||||||
chainState.Update();
|
//chainState.Update();
|
||||||
Assert.That(chainState.Requests.Length, Is.EqualTo(1));
|
//Assert.That(chainState.Requests.Length, Is.EqualTo(1));
|
||||||
|
|
||||||
purchaseContract.WaitForStorageContractStarted();
|
purchaseContract.WaitForStorageContractStarted();
|
||||||
chainState.Update();
|
//chainState.Update();
|
||||||
|
|
||||||
purchaseContract.WaitForStorageContractFinished();
|
purchaseContract.WaitForStorageContractFinished();
|
||||||
|
|
||||||
Thread.Sleep(rewarderInterval * 3);
|
Thread.Sleep(rewarderInterval * 3);
|
||||||
|
|
||||||
|
//running = false;
|
||||||
|
//task.Wait();
|
||||||
|
|
||||||
apiCalls.Stop();
|
apiCalls.Stop();
|
||||||
chainState.Update();
|
//chainState.Update();
|
||||||
|
|
||||||
foreach (var r in repo.Rewards)
|
foreach (var r in repo.Rewards)
|
||||||
{
|
{
|
||||||
@ -74,9 +87,9 @@ namespace CodexTests.UtilityTests
|
|||||||
return $"({rewardId})'{reward.Message}'";
|
return $"({rewardId})'{reward.Message}'";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommand(GiveRewardsCommand call)
|
private void OnCommand(string timestamp, GiveRewardsCommand call)
|
||||||
{
|
{
|
||||||
Log($"<API call>");
|
Log($"<API call {timestamp}>");
|
||||||
foreach (var a in call.Averages)
|
foreach (var a in call.Averages)
|
||||||
{
|
{
|
||||||
Log("\tAverage: " + JsonConvert.SerializeObject(a));
|
Log("\tAverage: " + JsonConvert.SerializeObject(a));
|
||||||
@ -249,14 +262,13 @@ namespace CodexTests.UtilityTests
|
|||||||
public class RewardApiCalls
|
public class RewardApiCalls
|
||||||
{
|
{
|
||||||
private readonly ContainerFileMonitor monitor;
|
private readonly ContainerFileMonitor monitor;
|
||||||
private readonly Dictionary<string, GiveRewardsCommand> commands = new Dictionary<string, GiveRewardsCommand>();
|
|
||||||
|
|
||||||
public RewardApiCalls(CoreInterface ci, RunningContainer botContainer)
|
public RewardApiCalls(ILog log, CoreInterface ci, RunningContainer botContainer)
|
||||||
{
|
{
|
||||||
monitor = new ContainerFileMonitor(ci, botContainer, "/app/datapath/logs/discordbot.log");
|
monitor = new ContainerFileMonitor(log, ci, botContainer, "/app/datapath/logs/discordbot.log");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start(Action<GiveRewardsCommand> onCommand)
|
public void Start(Action<string, GiveRewardsCommand> onCommand)
|
||||||
{
|
{
|
||||||
monitor.Start(line => ParseLine(line, onCommand));
|
monitor.Start(line => ParseLine(line, onCommand));
|
||||||
}
|
}
|
||||||
@ -266,19 +278,17 @@ namespace CodexTests.UtilityTests
|
|||||||
monitor.Stop();
|
monitor.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseLine(string line, Action<GiveRewardsCommand> onCommand)
|
private void ParseLine(string line, Action<string, GiveRewardsCommand> onCommand)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var timestamp = line.Substring(0, 30);
|
var timestamp = line.Substring(0, 30);
|
||||||
if (commands.ContainsKey(timestamp)) return;
|
|
||||||
var json = line.Substring(31);
|
var json = line.Substring(31);
|
||||||
|
|
||||||
var cmd = JsonConvert.DeserializeObject<GiveRewardsCommand>(json);
|
var cmd = JsonConvert.DeserializeObject<GiveRewardsCommand>(json);
|
||||||
if (cmd != null)
|
if (cmd != null)
|
||||||
{
|
{
|
||||||
commands.Add(timestamp, cmd);
|
onCommand(timestamp, cmd);
|
||||||
onCommand(cmd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@ -289,6 +299,7 @@ namespace CodexTests.UtilityTests
|
|||||||
|
|
||||||
public class ContainerFileMonitor
|
public class ContainerFileMonitor
|
||||||
{
|
{
|
||||||
|
private readonly ILog log;
|
||||||
private readonly CoreInterface ci;
|
private readonly CoreInterface ci;
|
||||||
private readonly RunningContainer botContainer;
|
private readonly RunningContainer botContainer;
|
||||||
private readonly string filePath;
|
private readonly string filePath;
|
||||||
@ -297,8 +308,9 @@ namespace CodexTests.UtilityTests
|
|||||||
private Task worker = Task.CompletedTask;
|
private Task worker = Task.CompletedTask;
|
||||||
private Action<string> onNewLine = c => { };
|
private Action<string> onNewLine = c => { };
|
||||||
|
|
||||||
public ContainerFileMonitor(CoreInterface ci, RunningContainer botContainer, string filePath)
|
public ContainerFileMonitor(ILog log, CoreInterface ci, RunningContainer botContainer, string filePath)
|
||||||
{
|
{
|
||||||
|
this.log = log;
|
||||||
this.ci = ci;
|
this.ci = ci;
|
||||||
this.botContainer = botContainer;
|
this.botContainer = botContainer;
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
@ -316,6 +328,9 @@ namespace CodexTests.UtilityTests
|
|||||||
worker.Wait();
|
worker.Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// did any container crash? that's why it repeats?
|
||||||
|
|
||||||
|
|
||||||
private void Worker()
|
private void Worker()
|
||||||
{
|
{
|
||||||
while (!cts.IsCancellationRequested)
|
while (!cts.IsCancellationRequested)
|
||||||
@ -333,6 +348,8 @@ namespace CodexTests.UtilityTests
|
|||||||
var lines = botLog.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
var lines = botLog.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (var line in lines)
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
|
// log.Log("line: " + line);
|
||||||
|
|
||||||
if (!seenLines.Contains(line))
|
if (!seenLines.Contains(line))
|
||||||
{
|
{
|
||||||
seenLines.Add(line);
|
seenLines.Add(line);
|
||||||
|
@ -19,19 +19,16 @@ namespace TestNetRewarder
|
|||||||
public void Debug(string message = "", int skipFrames = 0)
|
public void Debug(string message = "", int skipFrames = 0)
|
||||||
{
|
{
|
||||||
lines.Add(message);
|
lines.Add(message);
|
||||||
Trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Error(string message)
|
public void Error(string message)
|
||||||
{
|
{
|
||||||
lines.Add($"Error: {message}");
|
lines.Add($"Error: {message}");
|
||||||
Trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(string message)
|
public void Log(string message)
|
||||||
{
|
{
|
||||||
lines.Add(message);
|
lines.Add(message);
|
||||||
Trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] Get()
|
public string[] Get()
|
||||||
@ -40,13 +37,5 @@ namespace TestNetRewarder
|
|||||||
lines.Clear();
|
lines.Clear();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Trim()
|
|
||||||
{
|
|
||||||
if (lines.Count > 100)
|
|
||||||
{
|
|
||||||
lines.RemoveRange(0, 50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,15 +50,18 @@ namespace TestNetRewarder
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Error("Exception processing time segment: " + ex);
|
var msg = "Exception processing time segment: " + ex;
|
||||||
|
log.Error(msg);
|
||||||
|
bufferLogger.Error(msg);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] RemoveFirstLine(string[] lines)
|
private string[] RemoveFirstLine(string[] lines)
|
||||||
{
|
{
|
||||||
if (!lines.Any()) return Array.Empty<string>();
|
//if (!lines.Any()) return Array.Empty<string>();
|
||||||
return lines.Skip(1).ToArray();
|
//return lines.Skip(1).ToArray();
|
||||||
|
return lines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user