调整测试代码
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
priority int // 优先级,数字越大越优先
|
||||
updateInterval time.Duration // 更新间隔
|
||||
expireTime time.Duration
|
||||
logger logger.Logger
|
||||
@@ -15,7 +14,6 @@ type Options struct {
|
||||
|
||||
func defaultOptions() Options {
|
||||
return Options{
|
||||
priority: 0, // 默认优先级
|
||||
updateInterval: time.Second * 10,
|
||||
expireTime: time.Second * 32,
|
||||
logger: logger.NewLogger(),
|
||||
@@ -32,12 +30,6 @@ func newOptions(opts ...Option) Options {
|
||||
return o
|
||||
}
|
||||
|
||||
func SetPriority(priority int) Option {
|
||||
return func(o *Options) {
|
||||
o.priority = priority
|
||||
}
|
||||
}
|
||||
|
||||
func SetLogger(log logger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.logger = log
|
||||
|
||||
@@ -21,15 +21,15 @@ type Priority struct {
|
||||
expireTime time.Duration
|
||||
}
|
||||
|
||||
func InitPriority(ctx context.Context, re redis.UniversalClient, keyPrefix string, opts ...Option) *Priority {
|
||||
func InitPriority(ctx context.Context, re redis.UniversalClient, keyPrefix string, priority int, opts ...Option) *Priority {
|
||||
conf := newOptions(opts...)
|
||||
|
||||
pro := &Priority{
|
||||
ctx: ctx,
|
||||
priority: conf.priority,
|
||||
redis: re,
|
||||
logger: conf.logger,
|
||||
redisKey: "timer:priority_" + keyPrefix,
|
||||
ctx: ctx,
|
||||
priority: priority,
|
||||
redis: re,
|
||||
logger: conf.logger,
|
||||
redisKey: "timer:priority_" + keyPrefix,
|
||||
expireTime: conf.expireTime,
|
||||
}
|
||||
|
||||
|
||||
@@ -26,16 +26,30 @@ func TestPriority(t *testing.T) {
|
||||
re := getRedis()
|
||||
ctx := context.Background()
|
||||
|
||||
ctx,cancel := context.WithCancel(ctx)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
fmt.Println("ff")
|
||||
|
||||
pro := priority.InitPriority(ctx, re, "test", priority.SetUpdateInterval(time.Second*5))
|
||||
go func() {
|
||||
time.Sleep(time.Second * 5)
|
||||
|
||||
fmt.Println(pro)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
pro := priority.InitPriority(ctx, re, "test", 10, priority.SetUpdateInterval(time.Second*1))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
bb := pro.IsLatest(ctx)
|
||||
fmt.Println("cc:", bb)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
cancel()
|
||||
}()
|
||||
|
||||
pro := priority.InitPriority(ctx, re, "test", 0, priority.SetUpdateInterval(time.Second*1))
|
||||
|
||||
for i := 0; i < 25; i++ {
|
||||
bb := pro.IsLatest(ctx)
|
||||
fmt.Println("bb:", bb)
|
||||
time.Sleep(time.Second)
|
||||
|
||||
Reference in New Issue
Block a user