RynthSuite as of 2026-12-02 (internal 152e13d): release 2026.12.1.1

This commit is contained in:
Tom Bohar 2026-12-02 06:45:07 -05:00
commit 6b5a9c7e99
65 changed files with 3920 additions and 237 deletions

View file

@ -41,6 +41,7 @@ internal static unsafe class Program
var failed = new List<string>();
if (filter.Length == 0 && !CheckBuiltInVerbsMatchSwitch()) failed.Add("built-in /lua verbs");
if ((filter.Length == 0 || "memoryguard".Contains(filter, StringComparison.OrdinalIgnoreCase)) && !CheckMemoryGuard()) failed.Add("memory guard");
if ((filter.Length == 0 || "workers".Contains(filter, StringComparison.OrdinalIgnoreCase)) && !CheckWorkers()) failed.Add("worker coroutines");
try
{
foreach (string file in scripts)
@ -214,6 +215,71 @@ internal static unsafe class Program
return allOk;
}
/// <summary>
/// Worker coroutines (LuaScriptHost): MoonSharp makes ~1 MB of stacks per coroutine (2 MB in
/// this 64-bit test), so a coroutine per handler call made a 194-line /myquests read cost a
/// chat-handling script ~200 MB and got a script stopped by the memory guard (2026-11-30).
/// 300 chat lines through two handlers (one that errors every 50th line, one that sleeps
/// every 100th) must all arrive, reuse a handful of workers, and allocate far less than
/// 600 coroutines would.
/// </summary>
private static bool CheckWorkers()
{
const string name = "workerpool";
const string code = @"
seen, slept, errs = 0, 0, 0
game.World.OnChatText.Add(function(e)
seen = seen + 1
if e.Message:find('boom', 1, true) then errs = errs + 1; error('boom (expected)') end
end)
game.World.OnChatText.Add(function(e)
if e.Message:find('nap', 1, true) then sleep(30); slept = slept + 1 end
end)
while true do sleep(200); print('seen=' .. seen .. ' slept=' .. slept) end";
FakeWorld.W = new FakeWorld();
Harness.Reset();
RynthCoreApiNative api = FakeHost.Build();
var runtime = new RynthPluginRuntime<RynthLuaPlugin>();
if (runtime.Init(&api) != 0 || runtime.Plugin == null) { Console.WriteLine("FAIL worker coroutines: no plugin"); return false; }
RynthLuaPlugin plugin = runtime.Plugin;
bool ok;
try
{
plugin.OnLoginComplete();
for (int i = 0; i < 3; i++) Tick(plugin);
Directory.CreateDirectory(RynthLuaPaths.Scripts);
File.WriteAllText(Path.Combine(RynthLuaPaths.Scripts, name + ".lua"), code);
string? err = plugin.StartScript(name);
for (int i = 0; i < 5; i++) Tick(plugin);
int before = plugin.ScriptWorkersCreated(name);
long alloc0 = GC.GetAllocatedBytesForCurrentThread();
for (int i = 1; i <= 300; i++)
{
int eat = 0;
plugin.OnChatWindowText($"line {i}" + (i % 50 == 0 ? " boom" : "") + (i % 100 == 0 ? " nap" : ""), 0, ref eat);
if (i % 20 == 0) Tick(plugin);
}
var sw = Stopwatch.StartNew();
while (sw.ElapsedMilliseconds < 2000) { Tick(plugin); Thread.Sleep(1); }
long allocMb = (GC.GetAllocatedBytesForCurrentThread() - alloc0) >> 20;
int made = plugin.ScriptWorkersCreated(name) - before;
string console = plugin.ScriptConsoleText(name);
string[] lines = console.Split('\n');
int boom = lines.Count(l => l.Contains("boom (expected)", StringComparison.Ordinal));
bool loaded = plugin.ScriptIsLoaded(name);
string last = lines.LastOrDefault(l => l.StartsWith("seen=", StringComparison.Ordinal))?.Trim() ?? "(no count)";
// 300 lines x 2 handlers = 600 threads; errors (6) and sleepers drop or hold workers, the rest reuse.
ok = err == null && loaded && boom == 6 && last == "seen=300 slept=3" && made > 0 && made <= 40 && allocMb < 200;
Console.WriteLine($"{(ok ? "PASS" : "FAIL")} worker coroutines: 600 handler calls made {made} workers, {allocMb} MB allocated, {boom} handler errors, {last}, {(loaded ? "running" : "stopped")}{(err != null ? ", start error: " + err : "")}");
}
finally
{
try { plugin.StopScript(name); } catch { }
runtime.Shutdown();
}
return ok;
}
private static void Tick(RynthLuaPlugin plugin)
{
FakeWorld.W.Step();