调整测试代码
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
priority int // 优先级,数字越大越优先
|
|
||||||
updateInterval time.Duration // 更新间隔
|
updateInterval time.Duration // 更新间隔
|
||||||
expireTime time.Duration
|
expireTime time.Duration
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
@@ -15,7 +14,6 @@ type Options struct {
|
|||||||
|
|
||||||
func defaultOptions() Options {
|
func defaultOptions() Options {
|
||||||
return Options{
|
return Options{
|
||||||
priority: 0, // 默认优先级
|
|
||||||
updateInterval: time.Second * 10,
|
updateInterval: time.Second * 10,
|
||||||
expireTime: time.Second * 32,
|
expireTime: time.Second * 32,
|
||||||
logger: logger.NewLogger(),
|
logger: logger.NewLogger(),
|
||||||
@@ -32,12 +30,6 @@ func newOptions(opts ...Option) Options {
|
|||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetPriority(priority int) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.priority = priority
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetLogger(log logger.Logger) Option {
|
func SetLogger(log logger.Logger) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.logger = log
|
o.logger = log
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ type Priority struct {
|
|||||||
expireTime time.Duration
|
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...)
|
conf := newOptions(opts...)
|
||||||
|
|
||||||
pro := &Priority{
|
pro := &Priority{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
priority: conf.priority,
|
priority: priority,
|
||||||
redis: re,
|
redis: re,
|
||||||
logger: conf.logger,
|
logger: conf.logger,
|
||||||
redisKey: "timer:priority_" + keyPrefix,
|
redisKey: "timer:priority_" + keyPrefix,
|
||||||
|
|||||||
@@ -31,11 +31,25 @@ func TestPriority(t *testing.T) {
|
|||||||
|
|
||||||
fmt.Println("ff")
|
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)
|
bb := pro.IsLatest(ctx)
|
||||||
fmt.Println("bb:", bb)
|
fmt.Println("bb:", bb)
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|||||||
Reference in New Issue
Block a user