Rynzie02 commented on code in PR #1029:
URL: https://github.com/apache/dubbo-go-samples/pull/1029#discussion_r2772964271
##########
config_center/nacos/go-server/cmd/main.go:
##########
@@ -123,3 +123,42 @@ func main() {
logger.Error(err)
}
}
+
+func publishAndWaitConfig(
+ configClient config_client.IConfigClient,
+ dataID string,
+ group string,
+ content string,
+ timeout time.Duration,
+ pollInterval time.Duration,
+) error {
+ success, err := configClient.PublishConfig(vo.ConfigParam{
+ DataId: dataID,
+ Group: group,
+ Content: content,
+ })
+ if err != nil {
+ return err
+ }
+ if !success {
+ return fmt.Errorf("publish config failed")
+ }
+
+ deadline := time.Now().Add(timeout)
+ for {
+ current, err := configClient.GetConfig(vo.ConfigParam{
+ DataId: dataID,
+ Group: group,
+ })
+ if err == nil && strings.TrimSpace(current) ==
strings.TrimSpace(content) {
+ return nil
+ }
+ if time.Now().After(deadline) {
+ if err != nil {
+ return err
+ }
+ return fmt.Errorf("wait for config center timeout")
+ }
+ time.Sleep(pollInterval)
+ }
+}
Review Comment:
This function only appears in two places and doesn’t change often. I’d
prefer to keep it as-is to avoid adding a shared package and extra
dependencies.
##########
config_center/zookeeper/go-server/cmd/main.go:
##########
@@ -151,9 +148,31 @@ func writeRuleToConfigCenter() error {
logger.Info("Created new configuration in config center")
}
+ if err := waitForConfigReady(c, path, valueBytes, 10*time.Second); err
!= nil {
+ return perrors.Wrap(err, "wait for config ready")
+ }
+
return nil
}
+func waitForConfigReady(c *zk.Conn, path string, expected []byte, timeout
time.Duration) error {
+ deadline := time.Now().Add(timeout)
+ expectedStr := strings.TrimSpace(string(expected))
+ for {
+ data, _, err := c.Get(path)
+ if err == nil && strings.TrimSpace(string(data)) == expectedStr
{
+ return nil
+ }
+ if time.Now().After(deadline) {
+ if err != nil {
+ return perrors.Wrap(err, "wait for config
timeout")
+ }
+ return perrors.New("wait for config timeout")
+ }
+ time.Sleep(200 * time.Millisecond)
+ }
+}
Review Comment:
This function only appears in two places and doesn’t change often. I’d
prefer to keep it as-is to avoid adding a shared package and extra
dependencies.
##########
filter/sentinel/go-client/cmd/main.go:
##########
@@ -106,10 +137,20 @@ func main() {
logger.Info("call svc.GreetWithChanceOfError triggers circuit breaker
open")
CallGreetFunConcurrently(svc.GreetWithChanceOfError, "error", 1, 300)
- logger.Info("wait circuit breaker HalfOpen")
- time.Sleep(3 * time.Second)
+ if !waitForState(listener.openCh, 5*time.Second) {
+ logger.Warn("wait circuit breaker Open timeout")
+ }
+ logger.Info("wait circuit breaker HalfOpen window")
+ timer := time.NewTimer(retryTimeout + 200*time.Millisecond)
+ <-timer.C
+ timer.Stop()
Review Comment:
ok,I will remove in 1 commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]