DebugSessionManagerTests.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using IvfTl.ControlHost.Debug;
  3. using IvfTl.ControlHost.Tests.Fakes;
  4. using Xunit;
  5. namespace IvfTl.ControlHost.Tests
  6. {
  7. public class DebugSessionManagerTests
  8. {
  9. private DateTime _now = new DateTime(2026, 6, 23, 0, 0, 0);
  10. private (DebugSessionManager mgr, FakeGate gate) New(bool canAcquire = true)
  11. {
  12. var serial = new FakeSerial();
  13. var gate = new FakeGate(5, serial) { CanAcquire = canAcquire };
  14. var mgr = new DebugSessionManager(sn => gate, () => _now, ttlMs: 10000, log: _ => { });
  15. return (mgr, gate);
  16. }
  17. [Fact]
  18. public void Acquire_Returns_SessionId_And_Pauses()
  19. {
  20. var (mgr, gate) = New();
  21. var r = mgr.Acquire(5);
  22. Assert.True(r.Ok);
  23. Assert.False(string.IsNullOrEmpty((string)r.Result));
  24. Assert.True(gate.IsCapturePaused);
  25. }
  26. [Fact]
  27. public void Acquire_Busy_Returns_BUSY()
  28. {
  29. var (mgr, _) = New(canAcquire: false);
  30. var r = mgr.Acquire(5);
  31. Assert.False(r.Ok);
  32. Assert.Equal("BUSY", r.Code);
  33. }
  34. [Fact]
  35. public void Release_Disposes_Lease_And_Resumes()
  36. {
  37. var (mgr, gate) = New();
  38. string sid = (string)mgr.Acquire(5).Result;
  39. var r = mgr.Release(sid);
  40. Assert.True(r.Ok);
  41. Assert.True(gate.LastLease.Disposed);
  42. }
  43. [Fact]
  44. public void Release_Unknown_Session_Is_Idempotent_Ok()
  45. {
  46. var (mgr, _) = New();
  47. Assert.True(mgr.Release("not-a-session").Ok);
  48. }
  49. }
  50. }