diff options
author | Valery Piashchynski <[email protected]> | 2020-02-28 11:19:17 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-02-28 11:19:17 +0300 |
commit | 8240ea02181e80f8ac1347054e50718b4ba18ba0 (patch) | |
tree | 2feadfb93af68fc79edf1c4a18991c68e1a75462 /service | |
parent | 33f92daae1ecf9b9388cf3adb22a0efd2c3467d9 (diff) |
Resolve test issues
Diffstat (limited to 'service')
-rw-r--r-- | service/http/rpc_test.go | 9 | ||||
-rw-r--r-- | service/http/service_test.go | 5 | ||||
-rw-r--r-- | service/http/ssl_test.go | 15 |
3 files changed, 19 insertions, 10 deletions
diff --git a/service/http/rpc_test.go b/service/http/rpc_test.go index 1e5a18aa..1971f237 100644 --- a/service/http/rpc_test.go +++ b/service/http/rpc_test.go @@ -128,21 +128,24 @@ func Test_RPC_Unix(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + + time.Sleep(time.Second) res, _, err := get("http://localhost:6029") if err != nil { + c.Stop() t.Fatal(err) } if ss.rr.Workers() != nil && len(ss.rr.Workers()) > 0 { assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res) } else { + c.Stop() t.Fatal("no workers initialized") } cl, err := rs.Client() if err != nil { + c.Stop() t.Fatal(err) } @@ -152,10 +155,12 @@ func Test_RPC_Unix(t *testing.T) { res2, _, err := get("http://localhost:6029") if err != nil { + c.Stop() t.Fatal(err) } assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res2) assert.NotEqual(t, res, res2) + c.Stop() } func Test_Workers(t *testing.T) { diff --git a/service/http/service_test.go b/service/http/service_test.go index 2bb4b905..968230a7 100644 --- a/service/http/service_test.go +++ b/service/http/service_test.go @@ -351,8 +351,7 @@ func Test_Service_Middleware(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + time.Sleep(time.Second) req, err := http.NewRequest("GET", "http://localhost:6032?hello=world", nil) assert.NoError(t, err) @@ -386,8 +385,10 @@ func Test_Service_Middleware(t *testing.T) { err = r.Body.Close() if err != nil { + c.Stop() t.Errorf("error closing the Body: error %v", err) } + c.Stop() } func Test_Service_Listener(t *testing.T) { diff --git a/service/http/ssl_test.go b/service/http/ssl_test.go index 49bba6cb..fc8d5c54 100644 --- a/service/http/ssl_test.go +++ b/service/http/ssl_test.go @@ -109,8 +109,8 @@ func Test_SSL_Service_NoRedirect(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + + time.Sleep(time.Second) req, err := http.NewRequest("GET", "http://localhost:6029?hello=world", nil) assert.NoError(t, err) @@ -118,10 +118,7 @@ func Test_SSL_Service_NoRedirect(t *testing.T) { r, err := sslClient.Do(req) assert.NoError(t, err) defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("fail to close the Body: error %v", err) - } + }() assert.Nil(t, r.TLS) @@ -132,6 +129,12 @@ func Test_SSL_Service_NoRedirect(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 201, r.StatusCode) assert.Equal(t, "WORLD", string(b)) + + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("fail to close the Body: error %v", err2) + } + c.Stop() } func Test_SSL_Service_Redirect(t *testing.T) { |