diff --git a/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs b/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs index b2e184be..556ef152 100644 --- a/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs +++ b/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs @@ -50,6 +50,7 @@ namespace CodexDiscordBotPlugin startupConfig.Add(config); var pod = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig).WaitForOnline(); WaitForStartupMessage(workflow, pod); + workflow.CreateCrashWatcher(pod.Containers.Single()).Start(); return pod; } @@ -58,7 +59,9 @@ namespace CodexDiscordBotPlugin var startupConfig = new StartupConfig(); startupConfig.NameOverride = config.Name; startupConfig.Add(config); - return workflow.Start(1, new RewarderBotContainerRecipe(), startupConfig).WaitForOnline(); + var pod = workflow.Start(1, new RewarderBotContainerRecipe(), startupConfig).WaitForOnline(); + workflow.CreateCrashWatcher(pod.Containers.Single()).Start(); + return pod; } private void WaitForStartupMessage(IStartupWorkflow workflow, RunningPod pod) diff --git a/Tests/CodexTests/UtilityTests/DiscordBotTests.cs b/Tests/CodexTests/UtilityTests/DiscordBotTests.cs index 01c8fc5a..f78a46c6 100644 --- a/Tests/CodexTests/UtilityTests/DiscordBotTests.cs +++ b/Tests/CodexTests/UtilityTests/DiscordBotTests.cs @@ -1,5 +1,4 @@ using CodexContractsPlugin; -using CodexContractsPlugin.ChainMonitor; using CodexDiscordBotPlugin; using CodexPlugin; using Core; @@ -24,7 +23,9 @@ namespace CodexTests.UtilityTests private readonly List hostAccounts = new List(); private readonly List rewardsSeen = new List(); private readonly TimeSpan rewarderInterval = TimeSpan.FromMinutes(1); - + private readonly List receivedEvents = new List(); + private readonly List receivedAverages = new List(); + [Test] [DontDownloadLogs] public void BotRewardTest() @@ -39,37 +40,20 @@ namespace CodexTests.UtilityTests StartHosts(geth, contracts); var client = StartClient(geth, contracts); - //var chainState = new ChainState(GetTestLog(), contracts, new DoNothingChainEventHandler(), GetTestRunTimeRange().From); - - //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); var purchaseContract = ClientPurchasesStorage(client); - //chainState.Update(); - //Assert.That(chainState.Requests.Length, Is.EqualTo(1)); - purchaseContract.WaitForStorageContractStarted(); - //chainState.Update(); - purchaseContract.WaitForStorageContractFinished(); - Thread.Sleep(rewarderInterval * 3); - //running = false; - //task.Wait(); - apiCalls.Stop(); - //chainState.Update(); + + Assert.That(receivedEvents.Count(e => e.Contains("Created as New.")), Is.EqualTo(1)); + Assert.That(receivedEvents.Count(e => e.Contains("SlotFilled")), Is.EqualTo(GetNumberOfRequiredHosts())); + Assert.That(receivedEvents.Count(e => e.Contains("Transit: New -> Started")), Is.EqualTo(1)); + Assert.That(receivedEvents.Count(e => e.Contains("Transit: Started -> Finished")), Is.EqualTo(1)); foreach (var r in repo.Rewards) { @@ -90,10 +74,12 @@ namespace CodexTests.UtilityTests private void OnCommand(string timestamp, GiveRewardsCommand call) { Log($""); + receivedAverages.AddRange(call.Averages); foreach (var a in call.Averages) { Log("\tAverage: " + JsonConvert.SerializeObject(a)); } + receivedEvents.AddRange(call.EventsOverview); foreach (var e in call.EventsOverview) { Log("\tEvent: " + e); @@ -122,8 +108,8 @@ namespace CodexTests.UtilityTests MinRequiredNumberOfNodes = GetNumberOfRequiredHosts(), NodeFailureTolerance = 2, ProofProbability = 5, - Duration = TimeSpan.FromMinutes(6), - Expiry = TimeSpan.FromMinutes(5) + Duration = GetMinRequiredRequestDuration(), + Expiry = GetMinRequiredRequestDuration() - TimeSpan.FromMinutes(1) }; return client.Marketplace.RequestStorage(purchase); @@ -245,6 +231,11 @@ namespace CodexTests.UtilityTests return Convert.ToUInt32(repo.Rewards.Max(r => r.CheckConfig.MinNumberOfHosts)); } + private TimeSpan GetMinRequiredRequestDuration() + { + return repo.Rewards.Max(r => r.CheckConfig.MinDuration) + TimeSpan.FromSeconds(10); + } + private string IdentifyAccount(string address) { if (address == clientAccount.EthAddress.Address) return "Client";