summaryrefslogtreecommitdiff
path: root/service/health/service_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'service/health/service_test.go')
-rw-r--r--service/health/service_test.go54
1 files changed, 46 insertions, 8 deletions
diff --git a/service/health/service_test.go b/service/health/service_test.go
index 76462df9..d346d92b 100644
--- a/service/health/service_test.go
+++ b/service/health/service_test.go
@@ -66,7 +66,12 @@ func TestService_Serve(t *testing.T) {
assert.NotNil(t, hS)
assert.Equal(t, service.StatusOK, httpStatus)
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 500)
defer c.Stop()
@@ -104,13 +109,21 @@ func TestService_Serve_DeadWorker(t *testing.T) {
assert.NotNil(t, hS)
assert.Equal(t, service.StatusOK, httpStatus)
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("server error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 500)
defer c.Stop()
// Kill the worker
httpSvc := hS.(*rrhttp.Service)
- httpSvc.Server().Workers()[0].Kill()
+ err := httpSvc.Server().Workers()[0].Kill()
+ if err != nil {
+ t.Errorf("error killing the worker: error %v", err)
+ }
// Check health check
_, res, err := get("http://localhost:2116/")
@@ -147,13 +160,21 @@ func TestService_Serve_DeadWorkerStillHealthy(t *testing.T) {
assert.NotNil(t, hS)
assert.Equal(t, service.StatusOK, httpStatus)
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Second * 1)
defer c.Stop()
// Kill one of the workers
httpSvc := hS.(*rrhttp.Service)
- httpSvc.Server().Workers()[0].Kill()
+ err := httpSvc.Server().Workers()[0].Kill()
+ if err != nil {
+ t.Errorf("error killing the worker: error %v", err)
+ }
// Check health check
_, res, err := get("http://localhost:2116/")
@@ -210,7 +231,12 @@ func TestService_Serve_NoServer(t *testing.T) {
assert.NotNil(t, hS)
assert.Equal(t, service.StatusOK, httpStatus)
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 500)
defer c.Stop()
@@ -253,7 +279,12 @@ func TestService_Serve_NoPool(t *testing.T) {
assert.NotNil(t, hS)
assert.Equal(t, service.StatusOK, httpStatus)
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 500)
defer c.Stop()
@@ -271,8 +302,15 @@ func get(url string) (string, *http.Response, error) {
if err != nil {
return "", nil, err
}
- defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ return "", nil, err
+ }
+
+ err = r.Body.Close()
+ if err != nil {
+ return "", nil, err
+ }
return string(b), r, err
}