featurebase/hold/hold_test.go
2014-01-17 16:55:40 -06:00

31 lines
629 B
Go

package hold
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"tux21b.org/v1/gocql/uuid"
)
func TestHoldChan(t *testing.T) {
Hold := Holder{make(map[uuid.UUID]holdchan), make(chan gethold), make(chan delhold)}
go Hold.Run()
Convey("set then get", t, func() {
id := uuid.RandomUUID()
Hold.Set(&id, "derp", 10)
derp, _ := Hold.Get(&id, 10)
So(derp, ShouldEqual, "derp")
})
Convey("get then set", t, func() {
id := uuid.RandomUUID()
go func() {
Hold.Set(&id, "derpsy", 10)
}()
time.Sleep(time.Second / 10)
derp, _ := Hold.Get(&id, 10)
So(derp, ShouldEqual, "derpsy")
})
}