using System.Text.Json; namespace ZB.MOM.WW.ScadaBridge.Host.Tests; /// /// Pins the .NET runtime settings the Host ships in its *.runtimeconfig.json /// (Component-Host.md -> Runtime thread-pool settings). The Host's runtimeconfig is copied /// next to this test assembly because the test project references the Host executable, so /// the file read here is the one the build produces — the same file publish (and therefore /// the Docker image and the Windows service install) carries. /// public class RuntimeConfigTests { private static JsonElement ReadHostConfigProperties() { var path = Path.Combine(AppContext.BaseDirectory, "ZB.MOM.WW.ScadaBridge.Host.runtimeconfig.json"); Assert.True(File.Exists(path), $"Host runtimeconfig not found at {path}"); using var doc = JsonDocument.Parse(File.ReadAllText(path)); return doc.RootElement .GetProperty("runtimeOptions") .GetProperty("configProperties") .Clone(); } /// /// #146 (mirror of mxaccessgw#237): the thread pool's idle spin is capped at 10 steps /// (runtime default 70) so pool workers that find no work park instead of yielding /// with Sleep(0) dozens of times per work item. /// [Fact] public void Host_runtimeconfig_caps_thread_pool_unfair_semaphore_spin_at_10() { var props = ReadHostConfigProperties(); Assert.True( props.TryGetProperty("System.Threading.ThreadPool.UnfairSemaphoreSpinLimit", out var value), "System.Threading.ThreadPool.UnfairSemaphoreSpinLimit missing from the Host runtimeconfig"); Assert.Equal(10, value.GetInt32()); } }