| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using IvfTl.ControlHost.Debug;
- using IvfTl.ControlHost.Tests.Fakes;
- using Xunit;
- namespace IvfTl.ControlHost.Tests
- {
- public class DebugSessionManagerTests
- {
- private DateTime _now = new DateTime(2026, 6, 23, 0, 0, 0);
- private (DebugSessionManager mgr, FakeGate gate) New(bool canAcquire = true)
- {
- var serial = new FakeSerial();
- var gate = new FakeGate(5, serial) { CanAcquire = canAcquire };
- var mgr = new DebugSessionManager(sn => gate, () => _now, ttlMs: 10000, log: _ => { });
- return (mgr, gate);
- }
- [Fact]
- public void Acquire_Returns_SessionId_And_Pauses()
- {
- var (mgr, gate) = New();
- var r = mgr.Acquire(5);
- Assert.True(r.Ok);
- Assert.False(string.IsNullOrEmpty((string)r.Result));
- Assert.True(gate.IsCapturePaused);
- }
- [Fact]
- public void Acquire_Busy_Returns_BUSY()
- {
- var (mgr, _) = New(canAcquire: false);
- var r = mgr.Acquire(5);
- Assert.False(r.Ok);
- Assert.Equal("BUSY", r.Code);
- }
- [Fact]
- public void Release_Disposes_Lease_And_Resumes()
- {
- var (mgr, gate) = New();
- string sid = (string)mgr.Acquire(5).Result;
- var r = mgr.Release(sid);
- Assert.True(r.Ok);
- Assert.True(gate.LastLease.Disposed);
- }
- [Fact]
- public void Release_Unknown_Session_Is_Idempotent_Ok()
- {
- var (mgr, _) = New();
- Assert.True(mgr.Release("not-a-session").Ok);
- }
- }
- }
|