47 lines
810 B
Go
47 lines
810 B
Go
package mcp_test
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"gitea.d-ma.be/mathias/gitea-mcp/internal/mcp"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSessionStoreIssueAndCheck(t *testing.T) {
|
|
s := mcp.NewSessionStore()
|
|
|
|
id := s.Issue()
|
|
assert.NotEmpty(t, id)
|
|
assert.Len(t, id, 32)
|
|
|
|
assert.True(t, s.Valid(id))
|
|
assert.False(t, s.Valid("bogus"))
|
|
|
|
s.Drop(id)
|
|
assert.False(t, s.Valid(id))
|
|
}
|
|
|
|
func TestSessionStoreConcurrency(t *testing.T) {
|
|
s := mcp.NewSessionStore()
|
|
|
|
const goroutines = 32
|
|
const perGoroutine = 100
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(goroutines)
|
|
for i := 0; i < goroutines; i++ {
|
|
go func() {
|
|
defer wg.Done()
|
|
for j := 0; j < perGoroutine; j++ {
|
|
id := s.Issue()
|
|
if !s.Valid(id) {
|
|
t.Errorf("issued id %s reported invalid", id)
|
|
}
|
|
s.Drop(id)
|
|
}
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
}
|