using NATS.Server.Subscriptions;

namespace NATS.Server.Tests;

public class SubListAsyncCacheSweepTests
{
    [Fact]
    public async Task Cache_sweep_runs_async_and_prunes_stale_entries_without_write_locking_match_path()
    {
        using var sl = new SubList();
        sl.Insert(new Subscription { Subject = ">", Sid = "all" });

        for (var i = 0; i < 1500; i++)
            _ = sl.Match($"orders.{i}");

        var initial = sl.CacheCount;
        initial.ShouldBeGreaterThan(1024);

        await sl.TriggerCacheSweepAsyncForTest();
        sl.CacheCount.ShouldBeLessThan(initial);
    }
}
