featurebase/hold/hold_test.go
2014-06-18 15:09:31 -05:00

32 lines
628 B
Go

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