test: stop the 1 ms promotion window leaking out of StepCacheLifecycleTests (#2679)

## Summary

`Find_TwoPathfindsOverlappingChunks_PromoteToBuildOnSecondFind` fails intermittently in CI with `second Find through overlapping chunks must promote (got 0 builds)`.

**Cause:** `SecondTouchAfterWindow_RestartsTheCount` and `TwoFindsAcrossTheWindow_DoNotPromote` set `StepCache.Instance.MissPromotionWindowMs = 1` and never restore it, and `Clear()` does not reset it. Both classes share the `Sequential Pathfinding Tests` collection, so when a lifecycle test runs first, the promotion test's two Finds have to land within 1 ms of each other. On Linux, `Environment.TickCount` moves in coarse steps of several ms, so even a sub-millisecond test can see the window lapse. The second Find then restarts the miss count instead of promoting. On Windows the ~15.6 ms tick nearly always reads the same value for both Finds, which is why it didn't reproduce locally.

**Fix (tests only):**
- `StepCacheLifecycleTests` implements `IDisposable` and restores the window after each test.
- The promotion test sets the window it depends on (30 s) instead of inheriting it.

## Test plan

- [x] Reproduced deterministically: with a temporary 20 ms sleep between the two Finds, the test fails whenever the lifecycle tests run first and passes when run alone
- [x] With the sleep still in, the test passes with the Dispose restore alone and with both fixes
- [x] All pathfinding tests pass (123/123) with the sleep removed
This commit is contained in:
Kamron Batman 2026-09-25 00:55:07 -07:00 • committed by GitHub
parent 37a80e3447
commit 225c634bf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -371,6 +371,9 @@ public class BitmapAStarAlgorithmTests
{
StepCache.Instance.Clear();
StepCache.Instance.MissPromotionThreshold = 2;
// Pinned: promotion needs both Finds inside the window, and Linux's coarse TickCount can
// step several ms between two back-to-back Finds.
StepCache.Instance.MissPromotionWindowMs = 30_000;
var map = Map.Maps[1];
var stub = new DefaultWalkerStub();

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
@ -14,8 +15,14 @@ namespace Server.Tests.Pathfinding;
/// layers, and LRU eviction.
/// </summary>
[Collection("Sequential Pathfinding Tests")]
public class StepCacheLifecycleTests
public class StepCacheLifecycleTests : IDisposable
{
// The window is a knob on the singleton and Clear() leaves it alone, so a test that narrows
// it would otherwise leak the narrow window into every later test in the collection.
private readonly uint _savedWindowMs = StepCache.Instance.MissPromotionWindowMs;
public void Dispose() => StepCache.Instance.MissPromotionWindowMs = _savedWindowMs;
/// <summary>Resets to a known state and returns the singleton.</summary>
private static StepCache FreshCache(int promotionThreshold)
{