1
0
Fork 0
forked from External/grumble

Add package grumble/sessionpool for improved session ID reuse.

This commit is contained in:
Mikkel Krautz 2011-05-13 18:36:34 +02:00
parent 690e5bc750
commit 9703241e27
4 changed files with 154 additions and 0 deletions

View file

@ -0,0 +1,51 @@
package sessionpool
import (
"math"
"testing"
)
func TestReclaim(t *testing.T) {
pool := New()
id := pool.Get()
if id != 0 {
t.Errorf("Got %v, expected 0 (first time)", id)
}
pool.Reclaim(0)
id = pool.Get()
if id != 0 {
t.Errorf("Got %v, expected 0 (second time)", id)
}
id = pool.Get()
if id != 1 {
t.Errorf("Got %v, expected 1", id)
}
}
func TestDepletion(t *testing.T) {
defer func() {
r := recover()
if r != "SessionPool depleted" {
t.Errorf("Expected depletion panic")
}
}()
pool := New()
pool.next = math.MaxUint32
pool.Get()
}
func TestUseTracking(t *testing.T) {
defer func() {
r := recover()
if r != "Attempt to reclaim invalid session ID" {
t.Errorf("Expected reclamation panic")
}
}()
pool := New()
pool.EnableUseTracking()
pool.Reclaim(42)
}