session_test.go 602 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package mux_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/app/proxyman/mux"
  5. "v2ray.com/core/testing/assert"
  6. )
  7. func TestSessionManagerAdd(t *testing.T) {
  8. assert := assert.On(t)
  9. m := NewSessionManager()
  10. s := m.Allocate()
  11. assert.Uint16(s.ID).Equals(1)
  12. s = m.Allocate()
  13. assert.Uint16(s.ID).Equals(2)
  14. s = &Session{
  15. ID: 4,
  16. }
  17. m.Add(s)
  18. assert.Uint16(s.ID).Equals(4)
  19. }
  20. func TestSessionManagerClose(t *testing.T) {
  21. assert := assert.On(t)
  22. m := NewSessionManager()
  23. s := m.Allocate()
  24. assert.Bool(m.CloseIfNoSession()).IsFalse()
  25. m.Remove(s.ID)
  26. assert.Bool(m.CloseIfNoSession()).IsTrue()
  27. }