feat: port session 07 — Protocol Parser, Auth extras (TPM/certidp/certstore), Internal utilities & data structures
Session 07 scope (5 features, 17 tests, ~1165 Go LOC): - Protocol/ParserTypes.cs: ParserState enum (79 states), PublishArgument, ParseContext - Protocol/IProtocolHandler.cs: handler interface decoupling parser from client - Protocol/ProtocolParser.cs: Parse(), ProtoSnippet(), OverMaxControlLineLimit(), ProcessPub/HeaderPub/RoutedMsgArgs/RoutedHeaderMsgArgs, ClonePubArg(), GetHeader() - tests/Protocol/ProtocolParserTests.cs: 17 tests via TestProtocolHandler stub Auth extras from session 06 (committed separately): - Auth/TpmKeyProvider.cs, Auth/CertificateIdentityProvider/, Auth/CertificateStore/ Internal utilities & data structures (session 06 overflow): - Internal/AccessTimeService.cs, ElasticPointer.cs, SystemMemory.cs, ProcessStatsProvider.cs - Internal/DataStructures/GenericSublist.cs, HashWheel.cs - Internal/DataStructures/SubjectTree.cs, SubjectTreeNode.cs, SubjectTreeParts.cs All 461 tests pass (460 unit + 1 integration). DB updated for features 2588-2592 and tests 2598-2614.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using Shouldly;
|
||||
using ZB.MOM.NatsNet.Server.Internal;
|
||||
|
||||
namespace ZB.MOM.NatsNet.Server.Tests.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ProcessStatsProvider"/>, mirroring pse_test.go.
|
||||
/// The Go tests compare against `ps` command output — the .NET tests verify
|
||||
/// that values are within reasonable bounds since Process gives us the same data
|
||||
/// through a managed API without needing external command comparison.
|
||||
/// </summary>
|
||||
public sealed class ProcessStatsProviderTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task PSEmulationCPU_ShouldReturnReasonableValue()
|
||||
{
|
||||
// Mirror: TestPSEmulationCPU
|
||||
// Allow one sampling cycle to complete.
|
||||
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||
|
||||
ProcessStatsProvider.ProcUsage(out var pcpu, out _, out _);
|
||||
|
||||
// CPU % should be non-negative and at most 100% × processor count.
|
||||
pcpu.ShouldBeGreaterThanOrEqualTo(0);
|
||||
pcpu.ShouldBeLessThanOrEqualTo(100.0 * Environment.ProcessorCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PSEmulationMem_ShouldReturnReasonableValue()
|
||||
{
|
||||
// Mirror: TestPSEmulationMem
|
||||
ProcessStatsProvider.ProcUsage(out _, out var rss, out var vss);
|
||||
|
||||
// RSS should be at least 1 MB (any .NET process uses far more).
|
||||
rss.ShouldBeGreaterThan(1024L * 1024L);
|
||||
|
||||
// VSS should be at least as large as RSS.
|
||||
vss.ShouldBeGreaterThanOrEqualTo(rss);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PSEmulationWin_ShouldCacheAndRefresh()
|
||||
{
|
||||
// Mirror: TestPSEmulationWin (caching behaviour validation)
|
||||
ProcessStatsProvider.ProcUsage(out _, out var rss1, out _);
|
||||
ProcessStatsProvider.ProcUsage(out _, out var rss2, out _);
|
||||
|
||||
// Two immediate calls should return the same cached value.
|
||||
rss1.ShouldBe(rss2);
|
||||
|
||||
// After a sampling interval, values should still be valid.
|
||||
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||
ProcessStatsProvider.ProcUsage(out _, out var rssAfter, out _);
|
||||
rssAfter.ShouldBeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user