CatStation/Content.IntegrationTests/Tests/RoundEndTest.cs
Princess Cheeseballs 2c6ffecf62
Move GameTicker to Shared (#45834)
* Scope creep my ass

* why was this shit not pushed????

* gone...

* fix that

* review plus buildd

* asfsafsafsafsafas

* grug

* burber

* I'll fix this later

* shrimply die

* also this

* it's snerf or snuthin

* assaads

* round snend

* aaaa

* fix this shit for real

* actually, don't start GameRules until MapInit now that I think aboot it.

* forgot u

* don't actually need this part nullable

* Deffer comp removal

* one liner

* do that too

* chungus

* Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?)

* deferred removal :V

* aaaaaaaaaaaaaaa

* whhop

* Whoop

* better

* landmine that I placed for myself then forgot about lmao

* cleanup

* FUCKING `!`

* gotovo

* amogus

* please don't check by metadata I beg

* waawsasfdfsasfa

* sfafsasfafsas

* fdsaasffsasfa

* code

* fix

* fasasffasfasfsad

* chungaas

* I may be stupid

* gra

* graaaaaaaaaaaaaaaaa

* comment

* gra

* clearing is not predicted and would require major refactors, so don't cache on client.

* lame shit :P

* last holes

* nukeopsfsafsasafsfafsa

* why  was that shit public bruh

* bubrbgwahrghfaka

* dynamic

* revert change that did nothing lmao
2026-09-16 19:34:19 +00:00

161 lines
6.2 KiB
C#

using Content.IntegrationTests.Fixtures;
using Content.Server.GameTicking;
using Content.Server.RoundEnd;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
namespace Content.IntegrationTests.Tests
{
[TestFixture]
public sealed partial class RoundEndTest : GameTest
{
private sealed partial class RoundEndTestSystem : EntitySystem
{
public int RoundCount;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoundEndSystemChangedEvent>(OnRoundEnd);
}
private void OnRoundEnd(RoundEndSystemChangedEvent ev)
{
RoundCount += 1;
}
}
public override PoolSettings PoolSettings => new PoolSettings
{
DummyTicker = false,
Connected = true,
Dirty = true
};
[Test]
public async Task Test()
{
var pair = Pair;
var server = pair.Server;
var config = server.ResolveDependency<IConfigurationManager>();
var sysManager = server.ResolveDependency<IEntitySystemManager>();
var ticker = sysManager.GetEntitySystem<ServerGameTicker>();
var roundEndSystem = sysManager.GetEntitySystem<RoundEndSystem>();
var sys = server.System<RoundEndTestSystem>();
sys.RoundCount = 0;
await server.WaitAssertion(() =>
{
config.SetCVar(CCVars.GameLobbyEnabled, true);
config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, 1f);
config.SetCVar(CCVars.EmergencyShuttleDockTime, 1f);
config.SetCVar(CCVars.RoundRestartTime, 1f);
roundEndSystem.DefaultCooldownDuration = TimeSpan.FromMilliseconds(100);
roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMilliseconds(300);
});
await server.WaitAssertion(() =>
{
// Press the shuttle call button
roundEndSystem.RequestRoundEnd();
Assert.Multiple(() =>
{
Assert.That(roundEndSystem.ExpectedCountdownEnd, Is.Not.Null, "Shuttle was called, but countdown time was not set");
Assert.That(roundEndSystem.CanCallOrRecall(), Is.False, "Started the shuttle, but didn't have to wait cooldown to press cancel button");
});
// Check that we can't recall the shuttle yet
roundEndSystem.CancelRoundEndCountdown();
Assert.That(roundEndSystem.ExpectedCountdownEnd, Is.Not.Null, "Shuttle was cancelled, even though the button was on cooldown");
});
await WaitForEvent(); // Wait for Cooldown
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
Assert.That(roundEndSystem.CanCallOrRecall(), Is.True, "We waited a while, but the cooldown is not expired");
Assert.That(roundEndSystem.ExpectedCountdownEnd, Is.Not.Null, "We were waiting for the cooldown, but the round also ended");
});
// Recall the shuttle, which should trigger the cooldown again
roundEndSystem.CancelRoundEndCountdown();
Assert.Multiple(() =>
{
Assert.That(roundEndSystem.ExpectedCountdownEnd, Is.Null, "Recalled shuttle, but countdown has not ended");
Assert.That(roundEndSystem.CanCallOrRecall(), Is.False, "Recalled shuttle, but cooldown has not been enabled");
});
});
await WaitForEvent(); // Wait for Cooldown
await server.WaitAssertion(() =>
{
Assert.That(roundEndSystem.CanCallOrRecall(), Is.True, "We waited a while, but the cooldown is not expired");
// Press the shuttle call button
roundEndSystem.RequestRoundEnd();
});
await WaitForEvent(); // Wait for Cooldown
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
Assert.That(roundEndSystem.CanCallOrRecall(), Is.True, "We waited a while, but the cooldown is not expired");
Assert.That(roundEndSystem.ExpectedCountdownEnd, Is.Not.Null, "The countdown ended, but we just wanted the cooldown to end");
});
});
await WaitForEvent(); // Wait for countdown to end round
await CheckRunLevel(GameRunLevel.PostRound);
await WaitForEvent(); // Wait for Restart
await CheckRunLevel(GameRunLevel.PreRoundLobby);
Task CheckRunLevel(GameRunLevel level)
{
return server.WaitAssertion(() =>
{
Assert.That(ticker.RunLevel, Is.EqualTo(level));
});
}
async Task WaitForEvent()
{
const int maxTicks = 60;
var currentCount = sys.RoundCount;
for (var i = 0; i < maxTicks; i++)
{
if (currentCount != sys.RoundCount)
return;
await pair.RunTicksSync(1);
}
throw new TimeoutException("Event took too long to trigger");
}
// Need to clean self up
await server.WaitAssertion(() =>
{
config.SetCVar(CCVars.GameLobbyEnabled, false);
config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, CCVars.EmergencyShuttleMinTransitTime.DefaultValue);
config.SetCVar(CCVars.EmergencyShuttleDockTime, CCVars.EmergencyShuttleDockTime.DefaultValue);
config.SetCVar(CCVars.RoundRestartTime, CCVars.RoundRestartTime.DefaultValue);
roundEndSystem.DefaultCooldownDuration = TimeSpan.FromSeconds(30);
roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMinutes(4);
ticker.RestartRound();
});
}
}
}