This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 050f060  SCB-2176 Resolve comments (#993)
050f060 is described below

commit 050f0609a1c2114bab6202c2b8253d862a15cd86
Author: little-cui <[email protected]>
AuthorDate: Fri May 21 14:55:32 2021 +0800

    SCB-2176 Resolve comments (#993)
    
    * SCB-2176 Resolve comments
    
    * SCB-2176 Fix: UT panic
---
 server/connection/ws/websocket.go      | 7 +++----
 server/connection/ws/websocket_test.go | 8 ++++++--
 server/event/instance_subscriber.go    | 4 ++--
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/server/connection/ws/websocket.go 
b/server/connection/ws/websocket.go
index 0e9a7e0..c6d2f6b 100644
--- a/server/connection/ws/websocket.go
+++ b/server/connection/ws/websocket.go
@@ -19,13 +19,12 @@ package ws
 
 import (
        "context"
-       "fmt"
+       "errors"
        "time"
 
-       "github.com/apache/servicecomb-service-center/pkg/util"
-
        "github.com/apache/servicecomb-service-center/datasource"
        "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/pkg/util"
        "github.com/apache/servicecomb-service-center/server/connection"
        pb "github.com/go-chassis/cari/discovery"
        "github.com/gorilla/websocket"
@@ -33,7 +32,7 @@ import (
 
 const Websocket = "Websocket"
 
-var errServiceNotExist = fmt.Errorf("service does not exist")
+var errServiceNotExist = errors.New("service does not exist")
 
 type WebSocket struct {
        Options
diff --git a/server/connection/ws/websocket_test.go 
b/server/connection/ws/websocket_test.go
index 7518b5a..cd4ad8b 100644
--- a/server/connection/ws/websocket_test.go
+++ b/server/connection/ws/websocket_test.go
@@ -41,14 +41,17 @@ func init() {
 }
 
 type watcherConn struct {
+       MockServer *httptest.Server
        ClientConn *websocket.Conn
        ServerConn *websocket.Conn
 }
 
 func (h *watcherConn) Test() {
-       s := httptest.NewServer(h)
+       h.MockServer = httptest.NewServer(h)
        h.ClientConn, _, _ = websocket.DefaultDialer.Dial(
-               strings.Replace(s.URL, "http://";, "ws://", 1), nil)
+               strings.Replace(h.MockServer.URL, "http://";, "ws://", 1), nil)
+       // wait server is ready
+       <-time.After(time.Second)
 }
 
 func (h *watcherConn) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -66,6 +69,7 @@ func (h *watcherConn) ServeHTTP(w http.ResponseWriter, r 
*http.Request) {
                h.ServerConn.Close()
                return
        }
+       h.MockServer.Close()
 }
 
 func NewTest() *watcherConn {
diff --git a/server/event/instance_subscriber.go 
b/server/event/instance_subscriber.go
index fff474b..94dc76e 100644
--- a/server/event/instance_subscriber.go
+++ b/server/event/instance_subscriber.go
@@ -18,14 +18,14 @@
 package event
 
 import (
-       "fmt"
+       "errors"
 
        "github.com/apache/servicecomb-service-center/pkg/event"
        "github.com/apache/servicecomb-service-center/pkg/log"
        "github.com/apache/servicecomb-service-center/server/metrics"
 )
 
-var errBusy = fmt.Errorf("too busy")
+var errBusy = errors.New("too busy")
 
 type InstanceSubscriber struct {
        event.Subscriber

Reply via email to