From 1c6c9d6dcf6c94dabfc7347008480e43e7fbf20f Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 5 Aug 2019 01:28:14 -0500 Subject: [PATCH] increase timeouts in unstable tests --- backend/app/cmd/server_test.go | 14 +++++++------- backend/app/rest/api/rest_test.go | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index da72d6c5..bd3b6f79 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -88,7 +88,7 @@ func TestServerApp_DevMode(t *testing.T) { func TestServerApp_AnonMode(t *testing.T) { port := rand.Intn(40000) + 10000 - app, ctx := prepServerApp(t, 500*time.Millisecond, func(o ServerCommand) ServerCommand { + app, ctx := prepServerApp(t, 1000*time.Millisecond, func(o ServerCommand) ServerCommand { o.Port = port o.Auth.Anonymous = true return o @@ -104,7 +104,7 @@ func TestServerApp_AnonMode(t *testing.T) { resp, err := http.Get(fmt.Sprintf("http://localhost:%d/api/v1/ping", port)) require.Nil(t, err) defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) body, err := ioutil.ReadAll(resp.Body) assert.Nil(t, err) assert.Equal(t, "pong", string(body)) @@ -113,19 +113,19 @@ func TestServerApp_AnonMode(t *testing.T) { resp, err = http.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=blah123&aud=remark42", port)) require.Nil(t, err) defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) // try to login with bad name resp, err = http.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=**blah123&aud=remark42", port)) require.Nil(t, err) defer resp.Body.Close() - assert.Equal(t, 403, resp.StatusCode) + assert.Equal(t, http.StatusForbidden, resp.StatusCode) // try to login with short name resp, err = http.Get(fmt.Sprintf("http://localhost:%d/auth/anonymous/login?user=bl%20%20&aud=remark42", port)) require.Nil(t, err) defer resp.Body.Close() - assert.Equal(t, 403, resp.StatusCode) + assert.Equal(t, http.StatusForbidden, resp.StatusCode) app.Wait() } @@ -355,7 +355,7 @@ func TestServerAuthHooks(t *testing.T) { }) go func() { _ = app.run(ctx) }() - time.Sleep(100 * time.Millisecond) // let server start + time.Sleep(150 * time.Millisecond) // let server start // make a token for user dev tkService := app.restSrv.Authenticator.TokenService() @@ -378,7 +378,7 @@ func TestServerAuthHooks(t *testing.T) { t.Log(tk) // add comment - client := http.Client{Timeout: 1 * time.Second} + client := http.Client{Timeout: 2 * time.Second} req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/api/v1/comment", port), strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/p/2018/12/29/podcast-630/", "site": "remark"}}`)) require.NoError(t, err) diff --git a/backend/app/rest/api/rest_test.go b/backend/app/rest/api/rest_test.go index 84ab7d3d..5bc7694a 100644 --- a/backend/app/rest/api/rest_test.go +++ b/backend/app/rest/api/rest_test.go @@ -80,7 +80,7 @@ func TestRest_Shutdown(t *testing.T) { srv := Rest{Authenticator: &auth.Service{}, ImageProxy: &proxy.Image{}} go func() { - time.Sleep(100 * time.Millisecond) + time.Sleep(200 * time.Millisecond) srv.Shutdown() }() @@ -282,7 +282,6 @@ func TestRest_parseError(t *testing.T) { } func startupT(t *testing.T) (ts *httptest.Server, srv *Rest, teardown func()) { - // log.Setup(log.Out(ioutil.Discard)) log.Setup(log.CallerFile, log.CallerFunc, log.Msec, log.LevelBraces) testDb := fmt.Sprintf("/tmp/test-remark-%d.db", rand.Int31())