mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
update
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
package idgenerator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/charlienet/go-mixed/idGenerator/store"
|
||||
"github.com/charlienet/go-mixed/redis"
|
||||
@ -10,7 +13,7 @@ import (
|
||||
|
||||
func TestBufferAlloc(t *testing.T) {
|
||||
|
||||
tests.RunOnRedis(t, func(rdb redis.Client) {
|
||||
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
|
||||
f := func() (*store.Segment, error) {
|
||||
return store.NewRedisStore("sss", rdb).Assign(3, 99, 10)
|
||||
}
|
||||
@ -21,5 +24,28 @@ func TestBufferAlloc(t *testing.T) {
|
||||
t.Log(b.allot())
|
||||
}
|
||||
|
||||
}, redis.ReidsOption{Addr: "192.168.123.50:6379", Password: "123456"})
|
||||
})
|
||||
}
|
||||
|
||||
func TestTimeout(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
println("协程退出", ctx.Err().Error())
|
||||
case <-time.After(time.Second * 100):
|
||||
println("协程超时")
|
||||
}
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
println("应用退出")
|
||||
}
|
||||
|
Reference in New Issue
Block a user