github.com/eagleql/xray-core@v1.4.4/common/mux/session_test.go (about)

     1  package mux_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/eagleql/xray-core/common/mux"
     7  )
     8  
     9  func TestSessionManagerAdd(t *testing.T) {
    10  	m := NewSessionManager()
    11  
    12  	s := m.Allocate()
    13  	if s.ID != 1 {
    14  		t.Error("id: ", s.ID)
    15  	}
    16  	if m.Size() != 1 {
    17  		t.Error("size: ", m.Size())
    18  	}
    19  
    20  	s = m.Allocate()
    21  	if s.ID != 2 {
    22  		t.Error("id: ", s.ID)
    23  	}
    24  	if m.Size() != 2 {
    25  		t.Error("size: ", m.Size())
    26  	}
    27  
    28  	s = &Session{
    29  		ID: 4,
    30  	}
    31  	m.Add(s)
    32  	if s.ID != 4 {
    33  		t.Error("id: ", s.ID)
    34  	}
    35  	if m.Size() != 3 {
    36  		t.Error("size: ", m.Size())
    37  	}
    38  }
    39  
    40  func TestSessionManagerClose(t *testing.T) {
    41  	m := NewSessionManager()
    42  	s := m.Allocate()
    43  
    44  	if m.CloseIfNoSession() {
    45  		t.Error("able to close")
    46  	}
    47  	m.Remove(s.ID)
    48  	if !m.CloseIfNoSession() {
    49  		t.Error("not able to close")
    50  	}
    51  }