Files
ai-operator/internal/call/session_store_test.go
T

43 lines
834 B
Go

package call
import (
"fmt"
"sync"
"testing"
"time"
)
func TestSessionStoreCreateGetDelete(t *testing.T) {
store := NewSessionStore()
store.Create(&CallSession{AsteriskChannelID: "c1"})
if store.Count() != 1 {
t.Fatalf("count=%d", store.Count())
}
if _, ok := store.Get("c1"); !ok {
t.Fatal("missing c1")
}
store.Delete("missing")
store.Delete("c1")
if store.Count() != 0 {
t.Fatalf("count=%d", store.Count())
}
}
func TestSessionStoreConcurrent(t *testing.T) {
store := NewSessionStore()
var wg sync.WaitGroup
for i := 0; i < 50; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
id := fmt.Sprintf("c%d", i)
store.Create(&CallSession{AsteriskChannelID: id, StartedAt: time.Now()})
_, _ = store.Get(id)
}(i)
}
wg.Wait()
if store.Count() != 50 {
t.Fatalf("count=%d", store.Count())
}
}