Ss14 tests poolmanager

From space-sunrise/project-fire · View interactive version

Ss14 tests poolmanager is an AI agent skill from the GitHub repository space-sunrise/project-fire. An in-depth guide to the SS14 integration test framework: PoolManager, TestPair lifecycle, server/client synchronization, action emulation and pitfalls.

How to use this skill

Skill file

SS14 Integration Test Framework

When to use

Use this skill when needed:

If the task is specifically about designing and writing a new test as a product, use a separate skill ss14-tests-authoring. Here the focus is only on the infrastructure and execution mechanics.

Quality filter before transferring the pattern to work:

Pool model: what is important to remember :)

PairSettings sets the couple’s life policy:

Critical calculated properties:

public virtual bool MustNotBeReused => Destructive || NoLoadTestPrototypes;
public virtual bool MustBeNew => Fresh || NoLoadTestPrototypes;

Consequence:

How `PoolManager` selects and prepares a pair

The algorithm is essentially this:

  1. If MustBeNew, a new pair is created.
  2. Otherwise, a suitable one is taken from the pool.
  3. If CanFastRecycle(...) == true, only ApplySettings(...) applies.
  4. Otherwise, the full RecycleInternal(...) is executed.
  5. After the pair is issued, stabilization ticks and tick delta synchronization are run.

Practical conclusion:

Lifecycle couples and return to the pool ⚠️

Correct way:

  1. Take a pair.
  2. Execute the script.
  3. Call CleanReturnAsync().

What CleanReturnAsync() does:

If you don't call CleanReturnAsync(), dirty-dispose will work via DisposeAsync():

Server/client: correct execution contract

IIntegrationInstance has strict discipline:

Responsibilities cannot be mixed:

Specificity of `PoolSettings` in content

Setting options in content integration tests:

CanFastRecycle in the content additionally takes into account:

Emulate player actions

1) Enter (keybind)

In production code this is done through ClientFullInputCmdMessage and InputSystem.HandleInputCommand(...).

// Emulation of pressing keybind in a client instance.
var funcId = inputManager.NetworkBindMap.KeyFunctionID(ContentKeyFunctions.TryPullObject);
var msg = new ClientFullInputCmdMessage(client.Timing.CurTick, client.Timing.TickFraction, funcId)
{
    State = BoundKeyState.Down,
    Coordinates = client.EntMan.GetCoordinates(targetCoords),
    Uid = client.EntMan.GetEntity(targetNetEntity),
};

await client.WaitPost(() =>
{
    inputSystem.HandleInputCommand(clientSession, ContentKeyFunctions.TryPullObject, msg);
});

2) Click on the UI control

The standard way is to send Down + Up via GUIBoundKeyEventArgs and DoGuiEvent(...):

// Pressed the button.
await client.DoGuiEvent(control, downArgs);
await pair.RunTicksSync(1);

// Released the button.
await client.DoGuiEvent(control, upArgs);
await pair.RunTicksSync(1);

3) BUI message

After SendMessage(...) they usually give additional ticks for round-trip client↔server:

await client.WaitPost(() => bui.SendMessage(msg));
await pair.RunTicksSync(15); // handling reserve on both sides

4) Server interaction directly

For low-level interaction scenarios, use UserInteraction(...) inside WaitPost(...), and then wait for the consequences (do-after, target change, synchronization).

Patterns

Anti-patterns

Examples from actual code

Example A: basic borrow/return via pool

[Test]
public async Task RoundScenario_Works()
{
    await using var pair = await PoolManager.GetServerClient(new PoolSettings
    {
        Connected = true,
        Dirty = true,
        DummyTicker = false,
        InLobby = true,
    });

    // Let us stabilize the initial state of the pair.
    await pair.RunTicksSync(5);
    await pair.SyncTicks(targetDelta: 1);

    await pair.Server.WaitAssertion(() =>
    {
        var ticker = pair.Server.System<GameTicker>();
        Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
    });

    // An explicit clean-return is mandatory for the health of the pool.
    await pair.CleanReturnAsync();
}

Example B: Correct separation of Post and Assertion

EntityUid entity = default;

await server.WaitPost(() =>
{
    // Action only: create an entity.
    entity = server.EntMan.SpawnEntity("MobHuman", spawnCoords);
});

await server.WaitAssertion(() =>
{
    // Just checking: making sure that the entity exists.
    Assert.That(server.EntMan.EntityExists(entity), Is.True);
});

Example C: manual server/client start for a special case

var serverOpts = new ServerIntegrationOptions
{
    Pool = false,              // insulation, no reuse
    ExtraPrototypes = Prototypes,
};
var clientOpts = new ClientIntegrationOptions
{
    Pool = false,
    ExtraPrototypes = Prototypes,
};

var server = StartServer(serverOpts);
var client = StartClient(clientOpts);
await Task.WhenAll(server.WaitIdleAsync(), client.WaitIdleAsync());

Assert.DoesNotThrow(() => client.SetConnectTarget(server));
await client.WaitPost(() => client.ResolveDependency<IClientNetManager>().ClientConnect(null!, 0, null!));

Practical notes from the documentation

Use this as operational guidance, but check the CVar names and behavior against the current code.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.