From 50e437c22c1c822e19c1674e509afd73fc8fa7e2 Mon Sep 17 00:00:00 2001 From: Umputun Date: Thu, 4 Apr 2019 22:51:41 -0500 Subject: [PATCH] switch test port --- backend/app/main_test.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/backend/app/main_test.go b/backend/app/main_test.go index edc2e7e5..392985a1 100644 --- a/backend/app/main_test.go +++ b/backend/app/main_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "io/ioutil" "net/http" "os" @@ -11,6 +12,7 @@ import ( "time" log "github.com/go-pkgz/lgr" + "github.com/go-pkgz/repeater" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -23,12 +25,12 @@ func Test_Main(t *testing.T) { defer os.RemoveAll(dir) os.Args = []string{"test", "server", "--secret=123456", "--store.bolt.path=" + dir, "--backup=/tmp", - "--avatar.fs.path=" + dir, "--port=18202", "--url=https://demo.remark42.com", "--dbg", "--notify.type=none"} + "--avatar.fs.path=" + dir, "--port=18222", "--url=https://demo.remark42.com", "--dbg", "--notify.type=none"} go func() { time.Sleep(1000 * time.Millisecond) - err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM) - require.Nil(t, err) + e := syscall.Kill(syscall.Getpid(), syscall.SIGTERM) + require.Nil(t, e) }() wg := sync.WaitGroup{} @@ -40,16 +42,25 @@ func Test_Main(t *testing.T) { wg.Done() }() - time.Sleep(500 * time.Millisecond) // let server start + var passed bool + err = repeater.NewDefault(10, time.Millisecond*100).Do(context.Background(), func() error { + resp, e := http.Get("http://localhost:18222/api/v1/ping") + if e != nil { + t.Logf("%+v", e) + return e + } + require.Nil(t, e) + defer resp.Body.Close() + assert.Equal(t, 200, resp.StatusCode) + body, e := ioutil.ReadAll(resp.Body) + assert.Nil(t, e) + assert.Equal(t, "pong", string(body)) + passed = true + return nil + }) - // send ping - resp, err := http.Get("http://localhost:18202/api/v1/ping") - require.Nil(t, err) - defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) - body, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) - assert.Equal(t, "pong", string(body)) + assert.NoError(t, err) + assert.Equal(t, true, passed) wg.Wait() }