This is an automated email from the ASF dual-hosted git repository. littlecui 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 20e85923 [fix]frontend UT failure (#1316) 20e85923 is described below commit 20e859231cfdab94e1ba61120f6b83366e8946f8 Author: little-cui <sure_0...@qq.com> AuthorDate: Sat Jul 30 17:35:30 2022 +0800 [fix]frontend UT failure (#1316) --- frontend/server/server_test.go | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/frontend/server/server_test.go b/frontend/server/server_test.go index 2c46fbe5..5ff31e50 100644 --- a/frontend/server/server_test.go +++ b/frontend/server/server_test.go @@ -21,8 +21,8 @@ import ( "net/http" "os" "path/filepath" - "sync" "testing" + "time" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" @@ -39,20 +39,14 @@ func init() { } func TestStatic(t *testing.T) { - var wg sync.WaitGroup - cfg := Config{ SCAddr: "http://" + SCAddr, FrontendAddr: FrontAddr, } - wg.Add(1) - go func() { - wg.Done() - Serve(cfg) - }() + go Serve(cfg) + time.Sleep(500 * time.Millisecond) - wg.Wait() res, err := http.Get("http://" + FrontAddr) assert.NoError(t, err, "Error accessing frontend: %s", err) assert.Equal(t, http.StatusOK, res.StatusCode, "Expected http %d, got %d", http.StatusOK, res.StatusCode) @@ -60,10 +54,8 @@ func TestStatic(t *testing.T) { } func TestSCProxy(t *testing.T) { - var wg sync.WaitGroup greeting := "Hi, there!" - wg.Add(1) // simulate service center backend go func() { e := echo.New() @@ -71,11 +63,10 @@ func TestSCProxy(t *testing.T) { e.GET("/sayHi", func(c echo.Context) error { return c.String(http.StatusOK, greeting) }) - wg.Done() _ = e.Start(SCAddr) }() + time.Sleep(500 * time.Millisecond) - wg.Wait() res, err := http.Get("http://" + FrontAddr + "/sc/sayHi") assert.NoError(t, err, "Error accessing sc proxy: %s", err) assert.Equal(t, http.StatusOK, res.StatusCode, "Expected http %d, got %d", http.StatusOK, res.StatusCode) @@ -91,20 +82,14 @@ func TestSCProxy(t *testing.T) { } func TestDirectoryTraversal(t *testing.T) { - var wg sync.WaitGroup - cfg := Config{ SCAddr: "http://" + SCAddr, FrontendAddr: FrontAddr, } - wg.Add(1) - go func() { - wg.Done() - Serve(cfg) - }() + go Serve(cfg) + time.Sleep(500 * time.Millisecond) - wg.Wait() res, err := http.Get("http://" + FrontAddr + "/..\\schema/schemahandler.go") assert.NoError(t, err, "Error accessing frontend: %s", err) assert.Equal(t, http.StatusNotFound, res.StatusCode, "Expected http status is 404")