mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-08 01:58:34 +08:00
enhance: support clean paramtable config event in test (#30534)
relate: https://github.com/milvus-io/milvus/issues/30441 Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
This commit is contained in:
parent
77ba3ce3f3
commit
bbff9193d9
@ -211,6 +211,7 @@ func TestMultiRateLimiter(t *testing.T) {
|
|||||||
|
|
||||||
func TestRateLimiter(t *testing.T) {
|
func TestRateLimiter(t *testing.T) {
|
||||||
t.Run("test limit", func(t *testing.T) {
|
t.Run("test limit", func(t *testing.T) {
|
||||||
|
paramtable.Get().CleanEvent()
|
||||||
limiter := newRateLimiter(false)
|
limiter := newRateLimiter(false)
|
||||||
for _, rt := range internalpb.RateType_value {
|
for _, rt := range internalpb.RateType_value {
|
||||||
limiter.limiters.Insert(internalpb.RateType(rt), ratelimitutil.NewLimiter(ratelimitutil.Limit(1000), 1))
|
limiter.limiters.Insert(internalpb.RateType(rt), ratelimitutil.NewLimiter(ratelimitutil.Limit(1000), 1))
|
||||||
@ -226,6 +227,7 @@ func TestRateLimiter(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("test setRates", func(t *testing.T) {
|
t.Run("test setRates", func(t *testing.T) {
|
||||||
|
paramtable.Get().CleanEvent()
|
||||||
limiter := newRateLimiter(false)
|
limiter := newRateLimiter(false)
|
||||||
for _, rt := range internalpb.RateType_value {
|
for _, rt := range internalpb.RateType_value {
|
||||||
limiter.limiters.Insert(internalpb.RateType(rt), ratelimitutil.NewLimiter(ratelimitutil.Limit(1000), 1))
|
limiter.limiters.Insert(internalpb.RateType(rt), ratelimitutil.NewLimiter(ratelimitutil.Limit(1000), 1))
|
||||||
@ -266,6 +268,7 @@ func TestRateLimiter(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("test get error code", func(t *testing.T) {
|
t.Run("test get error code", func(t *testing.T) {
|
||||||
|
paramtable.Get().CleanEvent()
|
||||||
limiter := newRateLimiter(false)
|
limiter := newRateLimiter(false)
|
||||||
for _, rt := range internalpb.RateType_value {
|
for _, rt := range internalpb.RateType_value {
|
||||||
limiter.limiters.Insert(internalpb.RateType(rt), ratelimitutil.NewLimiter(ratelimitutil.Limit(1000), 1))
|
limiter.limiters.Insert(internalpb.RateType(rt), ratelimitutil.NewLimiter(ratelimitutil.Limit(1000), 1))
|
||||||
@ -295,6 +298,7 @@ func TestRateLimiter(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("tests refresh rate by config", func(t *testing.T) {
|
t.Run("tests refresh rate by config", func(t *testing.T) {
|
||||||
|
paramtable.Get().CleanEvent()
|
||||||
limiter := newRateLimiter(false)
|
limiter := newRateLimiter(false)
|
||||||
|
|
||||||
etcdCli, _ := etcd.GetEtcdClient(
|
etcdCli, _ := etcd.GetEtcdClient(
|
||||||
|
|||||||
@ -103,3 +103,10 @@ func (ed *EventDispatcher) Unregister(key string, handler EventHandler) {
|
|||||||
}
|
}
|
||||||
ed.registry[key] = newGroup
|
ed.registry[key] = newGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ed *EventDispatcher) Clean() {
|
||||||
|
ed.mut.Lock()
|
||||||
|
defer ed.mut.Unlock()
|
||||||
|
|
||||||
|
ed.registry = make(map[string][]EventHandler)
|
||||||
|
}
|
||||||
|
|||||||
@ -154,12 +154,19 @@ func (p *ComponentParam) Watch(key string, watcher config.EventHandler) {
|
|||||||
p.baseTable.mgr.Dispatcher.Register(key, watcher)
|
p.baseTable.mgr.Dispatcher.Register(key, watcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ComponentParam) WatchKeyPrefix(keyPrefix string, watcher config.EventHandler) {
|
||||||
|
p.baseTable.mgr.Dispatcher.RegisterForKeyPrefix(keyPrefix, watcher)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ComponentParam) Unwatch(key string, watcher config.EventHandler) {
|
func (p *ComponentParam) Unwatch(key string, watcher config.EventHandler) {
|
||||||
p.baseTable.mgr.Dispatcher.Unregister(key, watcher)
|
p.baseTable.mgr.Dispatcher.Unregister(key, watcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ComponentParam) WatchKeyPrefix(keyPrefix string, watcher config.EventHandler) {
|
// FOR TEST
|
||||||
p.baseTable.mgr.Dispatcher.RegisterForKeyPrefix(keyPrefix, watcher)
|
|
||||||
|
// clean all config event in dispatcher
|
||||||
|
func (p *ComponentParam) CleanEvent() {
|
||||||
|
p.baseTable.mgr.Dispatcher.Clean()
|
||||||
}
|
}
|
||||||
|
|
||||||
// /////////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user