Skip to content

Commit

Permalink
*: compute rev before firing go routines (pingcap#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox committed Mar 7, 2023
1 parent 2f68b7f commit 891bd6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/manager/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ func (e *ConfigManager) watch(ctx context.Context, ns, key string, f func(*zap.L
wkey := []byte(path.Join(e.basePath, ns, key))
logger := e.logger.With(zap.String("component", string(wkey)))
retryInterval := 5 * time.Second
rev := e.kv.Rev()
e.wg.Run(func() {
wch := e.kv.NewWatchStream()
defer wch.Close()
for {
if _, err := wch.Watch(mvcc.AutoWatchID, wkey, getPrefix(wkey), wch.Rev()); err == nil {
if _, err := wch.Watch(mvcc.AutoWatchID, wkey, getPrefix(wkey), rev); err == nil {
break
}
if k := retryInterval * 2; k < e.watchInterval {
Expand Down
6 changes: 2 additions & 4 deletions pkg/manager/config/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ func TestProxyConfig(t *testing.T) {
}

ch := cfgmgr.GetProxyConfigWatch()
require.Equal(t, <-ch, &config.ProxyServerOnline{})

for _, tc := range cases {
require.NoError(t, cfgmgr.SetProxyConfig(ctx, tc))
select {
case <-time.After(5 * time.Second):
t.Fatal("timeout waiting chan")
t.Fatalf("\n\ntimeout waiting chan\n\n")
case tg := <-ch:
for len(ch) > 0 {
tg = <-ch
}
require.Equal(t, tc, tg)
}
}
Expand Down

0 comments on commit 891bd6f

Please sign in to comment.