refactor: перенос логики сессии в internal/session и обновление mobile-фасада

This commit is contained in:
samosvalishe committed 2026-08-01 03:05:14 +03:00
1 parent 68485cbee7
commit 1f86fda104
55 files changed
+5314 -1312

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package tcpfwd
import (
"sync/atomic"
"testing"
)
// Зеркало активных сессий - единственный источник "сколько каналов поднято" для
// watchdog и UI в tcp-режиме: раньше счётчик оставался нулевым и сессию убивал
// таймаут подключения.
func TestSessionPoolMirrorsActiveCount(t *testing.T) {
var active atomic.Int32
pool := &SessionPool{active: &active}
first := pool.Add(1, nil)
if got := active.Load(); got != 1 {
t.Fatalf("active = %d, want 1", got)
}
second := pool.Add(2, nil)
if got := active.Load(); got != 2 {
t.Fatalf("active = %d, want 2", got)
}
pool.Remove(first)
if got := active.Load(); got != 1 {
t.Fatalf("active after remove = %d, want 1", got)
}
pool.Remove(second)
if got := active.Load(); got != 0 {
t.Fatalf("active after drain = %d, want 0", got)
}
if pool.Count() != 0 {
t.Fatalf("Count() = %d, want 0", pool.Count())
}
}
func TestSessionPoolWithoutMirror(t *testing.T) {
pool := &SessionPool{}
ps := pool.Add(1, nil)
pool.Remove(ps)
if pool.Count() != 0 {
t.Fatalf("Count() = %d, want 0", pool.Count())
}
}