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,80 @@
|
||||
using Shouldly;
|
||||
using ZB.MOM.NatsNet.Server.Internal;
|
||||
|
||||
namespace ZB.MOM.NatsNet.Server.Tests.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="AccessTimeService"/>, mirroring ats_test.go.
|
||||
/// </summary>
|
||||
[Collection("AccessTimeService")]
|
||||
public sealed class AccessTimeServiceTests : IDisposable
|
||||
{
|
||||
public AccessTimeServiceTests()
|
||||
{
|
||||
AccessTimeService.Reset();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
AccessTimeService.Reset();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotRunningValue_ShouldReturnNonZero()
|
||||
{
|
||||
// Mirror: TestNotRunningValue
|
||||
// No registrants; AccessTime() must still return a non-zero value.
|
||||
var at = AccessTimeService.AccessTime();
|
||||
at.ShouldBeGreaterThan(0);
|
||||
|
||||
// Should be stable (no background timer updating it).
|
||||
var atn = AccessTimeService.AccessTime();
|
||||
atn.ShouldBe(at);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RegisterAndUnregister_ShouldManageLifetime()
|
||||
{
|
||||
// Mirror: TestRegisterAndUnregister
|
||||
|
||||
AccessTimeService.Register();
|
||||
|
||||
var at = AccessTimeService.AccessTime();
|
||||
at.ShouldBeGreaterThan(0);
|
||||
|
||||
// Background timer should update the time.
|
||||
await Task.Delay(AccessTimeService.TickInterval * 3);
|
||||
var atn = AccessTimeService.AccessTime();
|
||||
atn.ShouldBeGreaterThan(at);
|
||||
|
||||
// Unregister; timer should stop.
|
||||
AccessTimeService.Unregister();
|
||||
await Task.Delay(AccessTimeService.TickInterval);
|
||||
|
||||
at = AccessTimeService.AccessTime();
|
||||
await Task.Delay(AccessTimeService.TickInterval * 3);
|
||||
atn = AccessTimeService.AccessTime();
|
||||
atn.ShouldBe(at);
|
||||
|
||||
// Re-register should restart the timer.
|
||||
AccessTimeService.Register();
|
||||
try
|
||||
{
|
||||
at = AccessTimeService.AccessTime();
|
||||
await Task.Delay(AccessTimeService.TickInterval * 3);
|
||||
atn = AccessTimeService.AccessTime();
|
||||
atn.ShouldBeGreaterThan(at);
|
||||
}
|
||||
finally
|
||||
{
|
||||
AccessTimeService.Unregister();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnbalancedUnregister_ShouldThrow()
|
||||
{
|
||||
// Mirror: TestUnbalancedUnregister
|
||||
Should.Throw<InvalidOperationException>(() => AccessTimeService.Unregister());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user