Files
AdamuSw/tests/MUnique.OpenMU.Tests/BotSelfHealingTest.cs
sven-n d04cbecae3 Merge pull request #820 from nolt/feature-bots
(cherry picked from commit b10de0645a869485fbb5771a739abd06b5708c2d)
2026-07-23 11:38:08 +03:00

50 lines
1.5 KiB
C#

// <copyright file="BotSelfHealingTest.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.Tests;
using MUnique.OpenMU.GameLogic.Bots;
/// <summary>
/// Tests how a bot reacts to its AI failing: the engine's attribute system is not thread-safe, and a
/// lost race can corrupt a character's attribute graph for good - from then on every tick throws, the
/// bot stops playing and floods the log. It asks for a restart, which rebuilds the graph and heals it.
/// </summary>
[TestFixture]
public class BotSelfHealingTest
{
/// <summary>
/// A tick failing now and then is simply skipped, like before - no restart.
/// </summary>
[Test]
public void SingleFailuresDoNotRestartTheBot()
{
var bot = new BotPlayer(GameContextTestHelper.CreateGameContext());
for (var i = 0; i < 100; i++)
{
bot.OnAiTickFailed();
bot.OnAiTickSucceeded();
}
Assert.That(bot.AwaitsFaultRestart, Is.False);
}
/// <summary>
/// A bot whose ticks keep failing is broken and asks the maintenance pass to restart it.
/// </summary>
[Test]
public void PersistentFailuresRestartTheBot()
{
var bot = new BotPlayer(GameContextTestHelper.CreateGameContext());
for (var i = 0; i < 20; i++)
{
bot.OnAiTickFailed();
}
Assert.That(bot.AwaitsFaultRestart, Is.True);
}
}