summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--error_buffer_test.go91
-rw-r--r--pipe_factory.go14
-rw-r--r--pipe_factory_test.go51
-rw-r--r--server_config_test.go33
-rw-r--r--server_test.go11
-rw-r--r--service/container.go5
-rw-r--r--service/container_test.go9
-rw-r--r--service/env/config_test.go5
-rw-r--r--service/env/service_test.go18
-rw-r--r--service/headers/service_test.go56
-rw-r--r--service/health/service_test.go54
-rw-r--r--service/http/attributes/attributes_test.go20
-rw-r--r--service/http/config.go15
-rw-r--r--service/http/handler_test.go737
-rw-r--r--service/limit/config_test.go5
-rw-r--r--service/limit/controller.go7
-rw-r--r--service/limit/service_test.go66
-rw-r--r--service/static/service_test.go70
-rw-r--r--socket_factory.go7
-rw-r--r--socket_factory_test.go208
-rw-r--r--static_pool.go8
-rw-r--r--static_pool_test.go29
-rw-r--r--worker.go15
23 files changed, 1279 insertions, 255 deletions
diff --git a/error_buffer_test.go b/error_buffer_test.go
index 81107935..c163ea43 100644
--- a/error_buffer_test.go
+++ b/error_buffer_test.go
@@ -7,16 +7,29 @@ import (
func TestErrBuffer_Write_Len(t *testing.T) {
buf := newErrBuffer()
- defer buf.Close()
-
- buf.Write([]byte("hello"))
+ defer func() {
+ err := buf.Close()
+ if err != nil {
+ t.Errorf("error during closing the buffer: error %v", err)
+ }
+ }()
+
+ _, err := buf.Write([]byte("hello"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
assert.Equal(t, 5, buf.Len())
assert.Equal(t, "hello", buf.String())
}
func TestErrBuffer_Write_Event(t *testing.T) {
buf := newErrBuffer()
- defer buf.Close()
+ defer func() {
+ err := buf.Close()
+ if err != nil {
+ t.Errorf("error during closing the buffer: error %v", err)
+ }
+ }()
tr := make(chan interface{})
buf.Listen(func(event int, ctx interface{}) {
@@ -25,8 +38,10 @@ func TestErrBuffer_Write_Event(t *testing.T) {
close(tr)
})
- buf.Write([]byte("hello\n"))
-
+ _, err := buf.Write([]byte("hello\n"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
<-tr
// messages are read
@@ -35,7 +50,12 @@ func TestErrBuffer_Write_Event(t *testing.T) {
func TestErrBuffer_Write_Event_Separated(t *testing.T) {
buf := newErrBuffer()
- defer buf.Close()
+ defer func() {
+ err := buf.Close()
+ if err != nil {
+ t.Errorf("error during closing the buffer: error %v", err)
+ }
+ }()
tr := make(chan interface{})
buf.Listen(func(event int, ctx interface{}) {
@@ -44,9 +64,20 @@ func TestErrBuffer_Write_Event_Separated(t *testing.T) {
close(tr)
})
- buf.Write([]byte("hel"))
- buf.Write([]byte("lo\n"))
- buf.Write([]byte("ending"))
+ _, err := buf.Write([]byte("hel"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
+
+ _, err = buf.Write([]byte("lo\n"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
+
+ _, err = buf.Write([]byte("ending"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
<-tr
assert.Equal(t, 0, buf.Len())
@@ -55,11 +86,27 @@ func TestErrBuffer_Write_Event_Separated(t *testing.T) {
func TestErrBuffer_Write_Event_Separated_NoListener(t *testing.T) {
buf := newErrBuffer()
- defer buf.Close()
-
- buf.Write([]byte("hel"))
- buf.Write([]byte("lo\n"))
- buf.Write([]byte("ending"))
+ defer func() {
+ err := buf.Close()
+ if err != nil {
+ t.Errorf("error during closing the buffer: error %v", err)
+ }
+ }()
+
+ _, err := buf.Write([]byte("hel"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
+
+ _, err = buf.Write([]byte("lo\n"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
+
+ _, err = buf.Write([]byte("ending"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
assert.Equal(t, 12, buf.Len())
assert.Equal(t, "hello\nending", buf.String())
@@ -67,9 +114,17 @@ func TestErrBuffer_Write_Event_Separated_NoListener(t *testing.T) {
func TestErrBuffer_Write_Remaining(t *testing.T) {
buf := newErrBuffer()
- defer buf.Close()
-
- buf.Write([]byte("hel"))
+ defer func() {
+ err := buf.Close()
+ if err != nil {
+ t.Errorf("error during closing the buffer: error %v", err)
+ }
+ }()
+
+ _, err := buf.Write([]byte("hel"))
+ if err != nil {
+ t.Errorf("fail to write: error %v", err)
+ }
assert.Equal(t, 3, buf.Len())
assert.Equal(t, "hel", buf.String())
diff --git a/pipe_factory.go b/pipe_factory.go
index d6fe0420..d8243d28 100644
--- a/pipe_factory.go
+++ b/pipe_factory.go
@@ -1,6 +1,7 @@
package roadrunner
import (
+ "fmt"
"github.com/pkg/errors"
"github.com/spiral/goridge"
"io"
@@ -45,11 +46,20 @@ func (f *PipeFactory) SpawnWorker(cmd *exec.Cmd) (w *Worker, err error) {
}
if pid, err := fetchPID(w.rl); pid != *w.Pid {
- go func(w *Worker) { w.Kill() }(w)
+ go func(w *Worker) {
+ err := w.Kill()
+ if err != nil {
+ // there is no logger here, how to handle error in goroutines ?
+ fmt.Println(fmt.Sprintf("error killing the worker with PID number %d, Created: %s", w.Pid, w.Created))
+ }
+ }(w)
if wErr := w.Wait(); wErr != nil {
if _, ok := wErr.(*exec.ExitError); ok {
- err = errors.Wrap(wErr, err.Error())
+ // error might be nil here
+ if err != nil {
+ err = errors.Wrap(wErr, err.Error())
+ }
} else {
err = wErr
}
diff --git a/pipe_factory_test.go b/pipe_factory_test.go
index 9d50e47f..e730d2cf 100644
--- a/pipe_factory_test.go
+++ b/pipe_factory_test.go
@@ -17,12 +17,18 @@ func Test_Pipe_Start(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Pipe_StartError(t *testing.T) {
cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- cmd.Start()
+ err := cmd.Start()
+ if err != nil {
+ t.Errorf("error running the command: error %v", err)
+ }
w, err := NewPipeFactory().SpawnWorker(cmd)
assert.Error(t, err)
@@ -31,7 +37,10 @@ func Test_Pipe_StartError(t *testing.T) {
func Test_Pipe_PipeError(t *testing.T) {
cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- cmd.StdinPipe()
+ _, err := cmd.StdinPipe()
+ if err != nil {
+ t.Errorf("error creating the STDIN pipe: error %v", err)
+ }
w, err := NewPipeFactory().SpawnWorker(cmd)
assert.Error(t, err)
@@ -40,7 +49,10 @@ func Test_Pipe_PipeError(t *testing.T) {
func Test_Pipe_PipeError2(t *testing.T) {
cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- cmd.StdoutPipe()
+ _, err := cmd.StdinPipe()
+ if err != nil {
+ t.Errorf("error creating the STDIN pipe: error %v", err)
+ }
w, err := NewPipeFactory().SpawnWorker(cmd)
assert.Error(t, err)
@@ -71,7 +83,12 @@ func Test_Pipe_Echo(t *testing.T) {
go func() {
assert.NoError(t, w.Wait())
}()
- defer w.Stop()
+ defer func() {
+ err := w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -93,7 +110,12 @@ func Test_Pipe_Broken(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "undefined_function()")
}()
- defer w.Stop()
+ defer func() {
+ err := w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -112,7 +134,10 @@ func Benchmark_Pipe_SpawnWorker_Stop(b *testing.B) {
}
}()
- w.Stop()
+ err := w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}
}
@@ -121,9 +146,17 @@ func Benchmark_Pipe_Worker_ExecEcho(b *testing.B) {
w, _ := NewPipeFactory().SpawnWorker(cmd)
go func() {
- w.Wait()
+ err := w.Wait()
+ if err != nil {
+ b.Errorf("error waiting the worker: error %v", err)
+ }
+ }()
+ defer func() {
+ err := w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}()
- defer w.Stop()
for n := 0; n < b.N; n++ {
if _, err := w.Exec(&Payload{Body: []byte("hello")}); err != nil {
diff --git a/server_config_test.go b/server_config_test.go
index 753da599..e408bde1 100644
--- a/server_config_test.go
+++ b/server_config_test.go
@@ -18,7 +18,12 @@ func Test_ServerConfig_PipeFactory(t *testing.T) {
f, err = cfg.makeFactory()
assert.NoError(t, err)
assert.NotNil(t, f)
- defer f.Close()
+ defer func() {
+ err := f.Close()
+ if err != nil {
+ t.Errorf("error closing factory or underlying connections: error %v", err)
+ }
+ }()
assert.NoError(t, err)
assert.IsType(t, &PipeFactory{}, f)
@@ -29,7 +34,12 @@ func Test_ServerConfig_SocketFactory(t *testing.T) {
f, err := cfg.makeFactory()
assert.NoError(t, err)
assert.NotNil(t, f)
- defer f.Close()
+ defer func() {
+ err := f.Close()
+ if err != nil {
+ t.Errorf("error closing factory or underlying connections: error %v", err)
+ }
+ }()
assert.NoError(t, err)
assert.IsType(t, &SocketFactory{}, f)
@@ -40,7 +50,12 @@ func Test_ServerConfig_SocketFactory(t *testing.T) {
f, err = cfg.makeFactory()
assert.NoError(t, err)
assert.NotNil(t, f)
- defer f.Close()
+ defer func() {
+ err := f.Close()
+ if err != nil {
+ t.Errorf("error closing factory or underlying connections: error %v", err)
+ }
+ }()
assert.NoError(t, err)
assert.IsType(t, &SocketFactory{}, f)
@@ -55,7 +70,12 @@ func Test_ServerConfig_UnixSocketFactory(t *testing.T) {
cfg := &ServerConfig{Relay: "unix://unix.sock"}
f, err := cfg.makeFactory()
- defer f.Close()
+ defer func() {
+ err := f.Close()
+ if err != nil {
+ t.Errorf("error closing factory or underlying connections: error %v", err)
+ }
+ }()
assert.NoError(t, err)
assert.IsType(t, &SocketFactory{}, f)
@@ -131,7 +151,10 @@ func Test_ServerConfigDefaults(t *testing.T) {
Command: "php tests/client.php pipes",
}
- cfg.InitDefaults()
+ err := cfg.InitDefaults()
+ if err != nil {
+ t.Errorf("error during the InitDefaults: error %v", err)
+ }
assert.Equal(t, "pipes", cfg.Relay)
assert.Equal(t, time.Minute, cfg.Pool.AllocateTimeout)
diff --git a/server_test.go b/server_test.go
index c973d634..9ab480b1 100644
--- a/server_test.go
+++ b/server_test.go
@@ -205,7 +205,10 @@ func TestServer_ReplacePool(t *testing.T) {
}
})
- rr.Reset()
+ err := rr.Reset()
+ if err != nil {
+ t.Errorf("error resetting the pool: error %v", err)
+ }
<-constructed
for _, w := range rr.Workers() {
@@ -239,9 +242,11 @@ func TestServer_ServerFailure(t *testing.T) {
rr.pool.(*StaticPool).cmd = func() *exec.Cmd {
return exec.Command("php", "tests/client.php", "echo", "broken-connection")
}
-
// killing random worker and expecting pool to replace it
- rr.Workers()[0].cmd.Process.Kill()
+ err := rr.Workers()[0].cmd.Process.Kill()
+ if err != nil {
+ t.Errorf("error killing the process: error %v", err)
+ }
<-failure
assert.True(t, true)
diff --git a/service/container.go b/service/container.go
index a21b49b4..b543ccb6 100644
--- a/service/container.go
+++ b/service/container.go
@@ -263,7 +263,10 @@ func (c *container) resolveValues(s interface{}, m reflect.Method, cfg Config) (
sc := reflect.New(v.Elem())
if dsc, ok := sc.Interface().(DefaultsConfig); ok {
- dsc.InitDefaults()
+ err := dsc.InitDefaults()
+ if err != nil {
+ return nil, err
+ }
if cfg == nil {
values = append(values, sc)
continue
diff --git a/service/container_test.go b/service/container_test.go
index 8fcaede2..33ad9491 100644
--- a/service/container_test.go
+++ b/service/container_test.go
@@ -67,7 +67,10 @@ type testCfg struct{ cfg string }
func (cfg *testCfg) Get(name string) Config {
vars := make(map[string]interface{})
- json.Unmarshal([]byte(cfg.cfg), &vars)
+ err := json.Unmarshal([]byte(cfg.cfg), &vars)
+ if err != nil {
+ panic("error unmarshalling the cfg.cfg value")
+ }
v, ok := vars[name]
if !ok {
@@ -435,9 +438,7 @@ func TestContainer_NoInit(t *testing.T) {
assert.NoError(t, c.Init(&testCfg{`{"test":"something", "test2":"something-else"}`}))
}
-type testInitD struct {
- c *testInitC
-}
+type testInitD struct {}
type DCfg struct {
V string
diff --git a/service/env/config_test.go b/service/env/config_test.go
index 50fbdaa5..226712c3 100644
--- a/service/env/config_test.go
+++ b/service/env/config_test.go
@@ -30,6 +30,9 @@ func Test_Config_Hydrate_Empty(t *testing.T) {
func Test_Config_Defaults(t *testing.T) {
c := &Config{}
- c.InitDefaults()
+ err := c.InitDefaults()
+ if err != nil {
+ t.Errorf("Test_Config_Defaults failed: error %v", err)
+ }
assert.Len(t, c.Values, 0)
}
diff --git a/service/env/service_test.go b/service/env/service_test.go
index c20bb76c..19cc03c7 100644
--- a/service/env/service_test.go
+++ b/service/env/service_test.go
@@ -11,8 +11,12 @@ func Test_NewService(t *testing.T) {
}
func Test_Init(t *testing.T) {
+ var err error
s := &Service{}
- s.Init(&Config{})
+ _, err = s.Init(&Config{})
+ if err != nil {
+ t.Errorf("error during the s.Init: error %v", err)
+ }
assert.Len(t, s.values, 1)
values, err := s.GetEnv()
@@ -21,9 +25,13 @@ func Test_Init(t *testing.T) {
}
func Test_Extend(t *testing.T) {
+ var err error
s := NewService(map[string]string{"RR": "version"})
- s.Init(&Config{Values: map[string]string{"key": "value"}})
+ _, err = s.Init(&Config{Values: map[string]string{"key": "value"}})
+ if err != nil {
+ t.Errorf("error during the s.Init: error %v", err)
+ }
assert.Len(t, s.values, 2)
values, err := s.GetEnv()
@@ -34,9 +42,13 @@ func Test_Extend(t *testing.T) {
}
func Test_Set(t *testing.T) {
+ var err error
s := NewService(map[string]string{"RR": "version"})
- s.Init(&Config{Values: map[string]string{"key": "value"}})
+ _, err = s.Init(&Config{Values: map[string]string{"key": "value"}})
+ if err != nil {
+ t.Errorf("error during the s.Init: error %v", err)
+ }
assert.Len(t, s.values, 2)
s.SetEnv("key", "value-new")
diff --git a/service/headers/service_test.go b/service/headers/service_test.go
index 250f4458..2f29db5e 100644
--- a/service/headers/service_test.go
+++ b/service/headers/service_test.go
@@ -59,7 +59,12 @@ func Test_RequestHeaders(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -68,7 +73,12 @@ func Test_RequestHeaders(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -103,7 +113,12 @@ func Test_ResponseHeaders(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -112,7 +127,12 @@ func Test_ResponseHeaders(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
assert.Equal(t, "output-header", r.Header.Get("output"))
@@ -157,7 +177,12 @@ func TestCORS_OPTIONS(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -166,7 +191,12 @@ func TestCORS_OPTIONS(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
assert.Equal(t, "true", r.Header.Get("Access-Control-Allow-Credentials"))
assert.Equal(t, "*", r.Header.Get("Access-Control-Allow-Headers"))
@@ -215,7 +245,12 @@ func TestCORS_Pass(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -224,7 +259,12 @@ func TestCORS_Pass(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
assert.Equal(t, "true", r.Header.Get("Access-Control-Allow-Credentials"))
assert.Equal(t, "*", r.Header.Get("Access-Control-Allow-Headers"))
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
}
diff --git a/service/http/attributes/attributes_test.go b/service/http/attributes/attributes_test.go
index a71d6542..2360fd12 100644
--- a/service/http/attributes/attributes_test.go
+++ b/service/http/attributes/attributes_test.go
@@ -10,7 +10,10 @@ func TestAllAttributes(t *testing.T) {
r := &http.Request{}
r = Init(r)
- Set(r, "key", "value")
+ err := Set(r, "key", "value")
+ if err != nil {
+ t.Errorf("error during the Set: error %v", err)
+ }
assert.Equal(t, All(r), map[string]interface{}{
"key": "value",
@@ -34,7 +37,10 @@ func TestGetAttribute(t *testing.T) {
r := &http.Request{}
r = Init(r)
- Set(r, "key", "value")
+ err := Set(r, "key", "value")
+ if err != nil {
+ t.Errorf("error during the Set: error %v", err)
+ }
assert.Equal(t, Get(r, "key"), "value")
}
@@ -55,13 +61,19 @@ func TestSetAttribute(t *testing.T) {
r := &http.Request{}
r = Init(r)
- Set(r, "key", "value")
+ err := Set(r, "key", "value")
+ if err != nil {
+ t.Errorf("error during the Set: error %v", err)
+ }
assert.Equal(t, Get(r, "key"), "value")
}
func TestSetAttributeNone(t *testing.T) {
r := &http.Request{}
- Set(r, "key", "value")
+ err := Set(r, "key", "value")
+ if err != nil {
+ t.Errorf("error during the Set: error %v", err)
+ }
assert.Equal(t, Get(r, "key"), nil)
}
diff --git a/service/http/config.go b/service/http/config.go
index ba3e6300..13a2cfc9 100644
--- a/service/http/config.go
+++ b/service/http/config.go
@@ -126,9 +126,18 @@ func (c *Config) Hydrate(cfg service.Config) error {
c.SSL.Port = 443
}
- c.HTTP2.InitDefaults()
- c.Uploads.InitDefaults()
- c.Workers.InitDefaults()
+ err := c.HTTP2.InitDefaults()
+ if err != nil {
+ return err
+ }
+ err = c.Uploads.InitDefaults()
+ if err != nil {
+ return err
+ }
+ err = c.Workers.InitDefaults()
+ if err != nil {
+ return err
+ }
if err := cfg.Unmarshal(c); err != nil {
return err
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index e29b76ac..91f0ca2b 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -23,9 +23,12 @@ func get(url string) (string, *http.Response, error) {
if err != nil {
return "", nil, err
}
- defer r.Body.Close()
-
b, err := ioutil.ReadAll(r.Body)
+
+ err = r.Body.Close()
+ if err != nil {
+ return "", nil, err
+ }
return string(b), r, err
}
@@ -44,9 +47,13 @@ func getHeader(url string, h map[string]string) (string, *http.Response, error)
if err != nil {
return "", nil, err
}
- defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
+
+ err = r.Body.Close()
+ if err != nil {
+ return "", nil, err
+ }
return string(b), r, err
}
@@ -74,9 +81,19 @@ func TestHandler_Echo(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
body, r, err := get("http://localhost:8177/?hello=world")
@@ -165,9 +182,19 @@ func TestHandler_Headers(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8078", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest("GET", "http://localhost:8078?hello=world", nil)
@@ -177,7 +204,13 @@ func TestHandler_Headers(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -212,9 +245,19 @@ func TestHandler_Empty_User_Agent(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8088", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest("GET", "http://localhost:8088?hello=world", nil)
@@ -224,7 +267,13 @@ func TestHandler_Empty_User_Agent(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -258,9 +307,19 @@ func TestHandler_User_Agent(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8088", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest("GET", "http://localhost:8088?hello=world", nil)
@@ -270,7 +329,13 @@ func TestHandler_User_Agent(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -304,9 +369,19 @@ func TestHandler_Cookies(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8079", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest("GET", "http://localhost:8079", nil)
@@ -316,7 +391,13 @@ func TestHandler_Cookies(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -355,9 +436,19 @@ func TestHandler_JsonPayload_POST(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8090", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest(
@@ -371,7 +462,13 @@ func TestHandler_JsonPayload_POST(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -405,9 +502,19 @@ func TestHandler_JsonPayload_PUT(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8081", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest("PUT", "http://localhost"+hs.Addr, bytes.NewBufferString(`{"key":"value"}`))
@@ -417,7 +524,13 @@ func TestHandler_JsonPayload_PUT(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -451,9 +564,19 @@ func TestHandler_JsonPayload_PATCH(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8082", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
req, err := http.NewRequest("PATCH", "http://localhost"+hs.Addr, bytes.NewBufferString(`{"key":"value"}`))
@@ -463,7 +586,13 @@ func TestHandler_JsonPayload_PATCH(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -497,9 +626,19 @@ func TestHandler_FormData_POST(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8083", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
form := url.Values{}
@@ -520,7 +659,13 @@ func TestHandler_FormData_POST(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -555,9 +700,19 @@ func TestHandler_FormData_POST_Overwrite(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8083", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
form := url.Values{}
@@ -572,7 +727,13 @@ func TestHandler_FormData_POST_Overwrite(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -607,9 +768,19 @@ func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8083", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
form := url.Values{}
@@ -630,7 +801,13 @@ func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -665,9 +842,19 @@ func TestHandler_FormData_PUT(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8084", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
form := url.Values{}
@@ -688,7 +875,13 @@ func TestHandler_FormData_PUT(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -723,9 +916,19 @@ func TestHandler_FormData_PATCH(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8085", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
form := url.Values{}
@@ -746,7 +949,13 @@ func TestHandler_FormData_PATCH(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -781,25 +990,72 @@ func TestHandler_Multipart_POST(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8019", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
var mb bytes.Buffer
w := multipart.NewWriter(&mb)
- w.WriteField("key", "value")
+ err := w.WriteField("key", "value")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
- w.WriteField("key", "value")
- w.WriteField("name[]", "name1")
- w.WriteField("name[]", "name2")
- w.WriteField("name[]", "name3")
- w.WriteField("arr[x][y][z]", "y")
- w.WriteField("arr[x][y][e]", "f")
- w.WriteField("arr[c]p", "l")
- w.WriteField("arr[c]z", "")
+ err = w.WriteField("key", "value")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("name[]", "name1")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
- w.Close()
+ err = w.WriteField("name[]", "name2")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("name[]", "name3")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[x][y][z]", "y")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[x][y][e]", "f")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[c]p", "l")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[c]z", "")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.Close()
+ if err != nil {
+ t.Errorf("error closing the writer: error %v", err)
+ }
req, err := http.NewRequest("POST", "http://localhost"+hs.Addr, &mb)
assert.NoError(t, err)
@@ -808,7 +1064,13 @@ func TestHandler_Multipart_POST(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -843,25 +1105,72 @@ func TestHandler_Multipart_PUT(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8020", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
var mb bytes.Buffer
w := multipart.NewWriter(&mb)
- w.WriteField("key", "value")
+ err := w.WriteField("key", "value")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
- w.WriteField("key", "value")
- w.WriteField("name[]", "name1")
- w.WriteField("name[]", "name2")
- w.WriteField("name[]", "name3")
- w.WriteField("arr[x][y][z]", "y")
- w.WriteField("arr[x][y][e]", "f")
- w.WriteField("arr[c]p", "l")
- w.WriteField("arr[c]z", "")
+ err = w.WriteField("key", "value")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
- w.Close()
+ err = w.WriteField("name[]", "name1")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("name[]", "name2")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("name[]", "name3")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[x][y][z]", "y")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[x][y][e]", "f")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[c]p", "l")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[c]z", "")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.Close()
+ if err != nil {
+ t.Errorf("error closing the writer: error %v", err)
+ }
req, err := http.NewRequest("PUT", "http://localhost"+hs.Addr, &mb)
assert.NoError(t, err)
@@ -870,7 +1179,13 @@ func TestHandler_Multipart_PUT(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -905,25 +1220,72 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8021", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
var mb bytes.Buffer
w := multipart.NewWriter(&mb)
- w.WriteField("key", "value")
+ err := w.WriteField("key", "value")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
- w.WriteField("key", "value")
- w.WriteField("name[]", "name1")
- w.WriteField("name[]", "name2")
- w.WriteField("name[]", "name3")
- w.WriteField("arr[x][y][z]", "y")
- w.WriteField("arr[x][y][e]", "f")
- w.WriteField("arr[c]p", "l")
- w.WriteField("arr[c]z", "")
+ err = w.WriteField("key", "value")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
- w.Close()
+ err = w.WriteField("name[]", "name1")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("name[]", "name2")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("name[]", "name3")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[x][y][z]", "y")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[x][y][e]", "f")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[c]p", "l")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.WriteField("arr[c]z", "")
+ if err != nil {
+ t.Errorf("error writing the field: error %v", err)
+ }
+
+ err = w.Close()
+ if err != nil {
+ t.Errorf("error closing the writer: error %v", err)
+ }
req, err := http.NewRequest("PATCH", "http://localhost"+hs.Addr, &mb)
assert.NoError(t, err)
@@ -932,7 +1294,13 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -967,9 +1335,19 @@ func TestHandler_Error(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
_, r, err := get("http://localhost:8177/?hello=world")
@@ -1001,9 +1379,19 @@ func TestHandler_Error2(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
_, r, err := get("http://localhost:8177/?hello=world")
@@ -1035,9 +1423,19 @@ func TestHandler_Error3(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
b2 := &bytes.Buffer{}
@@ -1050,7 +1448,13 @@ func TestHandler_Error3(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the closing Body: error %v", err)
+
+ }
+ }()
assert.NoError(t, err)
assert.Equal(t, 500, r.StatusCode)
@@ -1080,9 +1484,19 @@ func TestHandler_ResponseDuration(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
gotresp := make(chan interface{})
@@ -1129,9 +1543,19 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
gotresp := make(chan interface{})
@@ -1178,9 +1602,19 @@ func TestHandler_ErrorDuration(t *testing.T) {
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
goterr := make(chan interface{})
@@ -1231,15 +1665,28 @@ func TestHandler_IP(t *testing.T) {
}),
}
- h.cfg.parseCIDRs()
+ err := h.cfg.parseCIDRs()
+ if err != nil {
+ t.Errorf("error parsing CIDRs: error %v", err)
+ }
assert.NoError(t, h.rr.Start())
defer h.rr.Stop()
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
body, r, err := get("http://127.0.0.1:8177/")
@@ -1277,15 +1724,28 @@ func TestHandler_XRealIP(t *testing.T) {
}),
}
- h.cfg.parseCIDRs()
+ err := h.cfg.parseCIDRs()
+ if err != nil {
+ t.Errorf("error parsing CIDRs: error %v", err)
+ }
assert.NoError(t, h.rr.Start())
defer h.rr.Stop()
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
body, r, err := getHeader("http://127.0.0.1:8177/", map[string]string{
@@ -1328,15 +1788,27 @@ func TestHandler_XForwardedFor(t *testing.T) {
}),
}
- h.cfg.parseCIDRs()
-
+ err := h.cfg.parseCIDRs()
+ if err != nil {
+ t.Errorf("error parsing CIDRs: error %v", err)
+ }
assert.NoError(t, h.rr.Start())
defer h.rr.Stop()
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
body, r, err := getHeader("http://127.0.0.1:8177/", map[string]string{
@@ -1379,15 +1851,27 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
}),
}
- h.cfg.parseCIDRs()
-
+ err := h.cfg.parseCIDRs()
+ if err != nil {
+ t.Errorf("error parsing CIDRs: error %v", err)
+ }
assert.NoError(t, h.rr.Start())
defer h.rr.Stop()
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ t.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ t.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
body, r, err := getHeader("http://127.0.0.1:8177/", map[string]string{
@@ -1419,13 +1903,26 @@ func BenchmarkHandler_Listen_Echo(b *testing.B) {
}),
}
- h.rr.Start()
+ err := h.rr.Start()
+ if err != nil {
+ b.Errorf("error starting the worker pool: error %v", err)
+ }
defer h.rr.Stop()
hs := &http.Server{Addr: ":8177", Handler: h}
- defer hs.Shutdown(context.Background())
+ defer func() {
+ err := hs.Shutdown(context.Background())
+ if err != nil {
+ b.Errorf("error during the shutdown: error %v", err)
+ }
+ }()
- go func() { hs.ListenAndServe() }()
+ go func() {
+ err := hs.ListenAndServe()
+ if err != nil {
+ b.Errorf("error listening the interface: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 10)
bb := "WORLD"
@@ -1434,11 +1931,21 @@ func BenchmarkHandler_Listen_Echo(b *testing.B) {
if err != nil {
b.Fail()
}
- defer r.Body.Close()
-
- br, _ := ioutil.ReadAll(r.Body)
- if string(br) != bb {
- b.Fail()
+ // Response might be nil here
+ if r != nil {
+ br, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ b.Errorf("error reading Body: error %v", err)
+ }
+ if string(br) != bb {
+ b.Fail()
+ }
+ err = r.Body.Close()
+ if err != nil {
+ b.Errorf("error closing the Body: error %v", err)
+ }
+ } else {
+ b.Errorf("got nil response")
}
}
}
diff --git a/service/limit/config_test.go b/service/limit/config_test.go
index b8a6c0aa..b388791f 100644
--- a/service/limit/config_test.go
+++ b/service/limit/config_test.go
@@ -31,7 +31,10 @@ func Test_Controller_Default(t *testing.T) {
}
`}
c := &Config{}
- c.InitDefaults()
+ err := c.InitDefaults()
+ if err != nil {
+ t.Errorf("failed to InitDefaults: error %v", err)
+ }
assert.NoError(t, c.Hydrate(cfg))
assert.Equal(t, time.Second, c.Interval)
diff --git a/service/limit/controller.go b/service/limit/controller.go
index c11f4b91..24a158f7 100644
--- a/service/limit/controller.go
+++ b/service/limit/controller.go
@@ -66,7 +66,12 @@ func (c *controller) control(p roadrunner.Pool) {
// make sure worker still on initial request
if p.Remove(w, err) && w.State().NumExecs() == eID {
- go w.Kill()
+ go func() {
+ err := w.Kill()
+ if err != nil {
+ fmt.Printf("error killing worker with PID number: %d, created: %s", w.Pid, w.Created)
+ }
+ }()
c.report(EventExecTTL, w, err)
}
}
diff --git a/service/limit/service_test.go b/service/limit/service_test.go
index ade4abcc..8cb3d7dc 100644
--- a/service/limit/service_test.go
+++ b/service/limit/service_test.go
@@ -75,7 +75,12 @@ func Test_Service_PidEcho(t *testing.T) {
s, _ := c.Get(rrhttp.ID)
assert.NotNil(t, s)
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -84,7 +89,12 @@ func Test_Service_PidEcho(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -129,7 +139,12 @@ func Test_Service_ListenerPlusTTL(t *testing.T) {
}
})
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -140,7 +155,12 @@ func Test_Service_ListenerPlusTTL(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -194,7 +214,12 @@ func Test_Service_ListenerPlusIdleTTL(t *testing.T) {
}
})
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -205,7 +230,12 @@ func Test_Service_ListenerPlusIdleTTL(t *testing.T) {
r, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
- defer r.Body.Close()
+ defer func() {
+ err := r.Body.Close()
+ if err != nil {
+ t.Errorf("error during the body closing: error %v", err)
+ }
+ }()
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
@@ -261,7 +291,12 @@ func Test_Service_Listener_MaxExecTTL(t *testing.T) {
}
})
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -313,7 +348,12 @@ func Test_Service_Listener_MaxMemoryUsage(t *testing.T) {
}
})
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -325,11 +365,17 @@ func Test_Service_Listener_MaxMemoryUsage(t *testing.T) {
for {
select {
case <-captured:
- http.DefaultClient.Do(req)
+ _, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Errorf("error during sending the http request: error %v", err)
+ }
assert.NotEqual(t, lastPID, getPID(s))
return
default:
- http.DefaultClient.Do(req)
+ _, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Errorf("error during sending the http request: error %v", err)
+ }
}
}
}
diff --git a/service/static/service_test.go b/service/static/service_test.go
index d345b138..309804cc 100644
--- a/service/static/service_test.go
+++ b/service/static/service_test.go
@@ -41,9 +41,17 @@ 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
}
@@ -76,7 +84,12 @@ func Test_Files(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -129,7 +142,12 @@ func Test_Files_Disable(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -226,7 +244,12 @@ func Test_Files_Forbid(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -263,7 +286,12 @@ func Test_Files_Always(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -300,7 +328,12 @@ func Test_Files_NotFound(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -337,7 +370,12 @@ func Test_Files_Dir(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -374,7 +412,12 @@ func Test_Files_NotForbid(t *testing.T) {
}
}`}))
- go func() { c.Serve() }()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("serve error: %v", err)
+ }
+ }()
time.Sleep(time.Millisecond * 100)
defer c.Stop()
@@ -391,10 +434,17 @@ func tmpDir() string {
func all(fn string) string {
f, _ := os.Open(fn)
- defer f.Close()
b := &bytes.Buffer{}
- io.Copy(b, f)
+ _, err := io.Copy(b, f)
+ if err != nil {
+ return ""
+ }
+
+ err = f.Close()
+ if err != nil {
+ return ""
+ }
return b.String()
}
diff --git a/socket_factory.go b/socket_factory.go
index 43059e8a..8a1b4d67 100644
--- a/socket_factory.go
+++ b/socket_factory.go
@@ -51,7 +51,12 @@ func (f *SocketFactory) SpawnWorker(cmd *exec.Cmd) (w *Worker, err error) {
rl, err := f.findRelay(w, f.tout)
if err != nil {
- go func(w *Worker) { w.Kill() }(w)
+ go func(w *Worker) {
+ err := w.Kill()
+ if err != nil {
+ fmt.Println(fmt.Errorf("error killing the worker %w", err))
+ }
+ }(w)
if wErr := w.Wait(); wErr != nil {
if _, ok := wErr.(*exec.ExitError); ok {
diff --git a/socket_factory_test.go b/socket_factory_test.go
index 56d9313e..e718f6c2 100644
--- a/socket_factory_test.go
+++ b/socket_factory_test.go
@@ -14,7 +14,12 @@ func Test_Tcp_Start(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -29,7 +34,10 @@ func Test_Tcp_Start(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Tcp_StartCloseFactory(t *testing.T) {
@@ -44,7 +52,12 @@ func Test_Tcp_StartCloseFactory(t *testing.T) {
cmd := exec.Command("php", "tests/client.php", "echo", "tcp")
f := NewSocketFactory(ls, time.Minute)
- defer f.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
w, err := f.SpawnWorker(cmd)
assert.NoError(t, err)
@@ -54,7 +67,10 @@ func Test_Tcp_StartCloseFactory(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Tcp_StartError(t *testing.T) {
@@ -62,13 +78,21 @@ func Test_Tcp_StartError(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- cmd.Start()
+ err = cmd.Start()
+ if err != nil {
+ t.Errorf("error executing the command: error %v", err)
+ }
w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
assert.Error(t, err)
@@ -80,7 +104,12 @@ func Test_Tcp_Failboot(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -98,7 +127,12 @@ func Test_Tcp_Timeout(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -116,7 +150,12 @@ func Test_Tcp_Invalid(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -133,7 +172,12 @@ func Test_Tcp_Broken(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -147,7 +191,12 @@ func Test_Tcp_Broken(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "undefined_function()")
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -160,7 +209,12 @@ func Test_Tcp_Echo(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -171,7 +225,12 @@ func Test_Tcp_Echo(t *testing.T) {
go func() {
assert.NoError(t, w.Wait())
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -190,7 +249,12 @@ func Test_Unix_Start(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -205,7 +269,10 @@ func Test_Unix_Start(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Unix_Failboot(t *testing.T) {
@@ -215,7 +282,12 @@ func Test_Unix_Failboot(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -235,7 +307,12 @@ func Test_Unix_Timeout(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -255,7 +332,12 @@ func Test_Unix_Invalid(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -274,7 +356,12 @@ func Test_Unix_Broken(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -288,7 +375,12 @@ func Test_Unix_Broken(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "undefined_function()")
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -303,7 +395,12 @@ func Test_Unix_Echo(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -314,7 +411,12 @@ func Test_Unix_Echo(t *testing.T) {
go func() {
assert.NoError(t, w.Wait())
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -329,7 +431,12 @@ func Test_Unix_Echo(t *testing.T) {
func Benchmark_Tcp_SpawnWorker_Stop(b *testing.B) {
ls, err := net.Listen("tcp", "localhost:9007")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -345,14 +452,22 @@ func Benchmark_Tcp_SpawnWorker_Stop(b *testing.B) {
}
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}
}
func Benchmark_Tcp_Worker_ExecEcho(b *testing.B) {
ls, err := net.Listen("tcp", "localhost:9007")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -361,9 +476,17 @@ func Benchmark_Tcp_Worker_ExecEcho(b *testing.B) {
w, _ := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
go func() {
- w.Wait()
+ err := w.Wait()
+ if err != nil {
+ b.Errorf("error waiting: %v", err)
+ }
+ }()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}()
- defer w.Stop()
for n := 0; n < b.N; n++ {
if _, err := w.Exec(&Payload{Body: []byte("hello")}); err != nil {
@@ -379,7 +502,12 @@ func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -395,7 +523,10 @@ func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) {
}
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}
}
@@ -406,7 +537,12 @@ func Benchmark_Unix_Worker_ExecEcho(b *testing.B) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -415,9 +551,17 @@ func Benchmark_Unix_Worker_ExecEcho(b *testing.B) {
w, _ := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
go func() {
- w.Wait()
+ err := w.Wait()
+ if err != nil {
+ b.Errorf("error waiting: %v", err)
+ }
+ }()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}()
- defer w.Stop()
for n := 0; n < b.N; n++ {
if _, err := w.Exec(&Payload{Body: []byte("hello")}); err != nil {
diff --git a/static_pool.go b/static_pool.go
index 66b1366e..735bc701 100644
--- a/static_pool.go
+++ b/static_pool.go
@@ -42,7 +42,6 @@ type StaticPool struct {
workers []*Worker
// invalid declares set of workers to be removed from the pool.
- mur sync.Mutex
remove sync.Map
// pool is being destroyed
@@ -294,7 +293,12 @@ func (p *StaticPool) discardWorker(w *Worker, caused interface{}) {
// destroyWorker destroys workers and removes it from the pool.
func (p *StaticPool) destroyWorker(w *Worker, caused interface{}) {
- go w.Stop()
+ go func() {
+ err := w.Stop()
+ if err != nil {
+ p.throw(EventWorkerError, WorkerError{Worker: w, Caused: err})
+ }
+ }()
select {
case <-w.waitDone:
diff --git a/static_pool_test.go b/static_pool_test.go
index a7e71fdb..f5313f6b 100644
--- a/static_pool_test.go
+++ b/static_pool_test.go
@@ -23,12 +23,13 @@ func Test_NewPool(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
+
assert.Equal(t, cfg, p.Config())
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
}
func Test_StaticPool_Invalid(t *testing.T) {
@@ -62,10 +63,11 @@ func Test_StaticPool_Echo(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
+
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
res, err := p.Exec(&Payload{Body: []byte("hello")})
@@ -83,10 +85,11 @@ func Test_StaticPool_Echo_NilContext(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
+
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
res, err := p.Exec(&Payload{Body: []byte("hello"), Context: nil})
@@ -104,10 +107,11 @@ func Test_StaticPool_Echo_Context(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
+
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
res, err := p.Exec(&Payload{Body: []byte("hello"), Context: []byte("world")})
@@ -125,10 +129,10 @@ func Test_StaticPool_JobError(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
res, err := p.Exec(&Payload{Body: []byte("hello")})
@@ -145,10 +149,10 @@ func Test_StaticPool_Broken_Replace(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
p.Listen(func(e int, ctx interface{}) {
if err, ok := ctx.(error); ok {
@@ -168,10 +172,10 @@ func Test_StaticPool_Broken_FromOutside(t *testing.T) {
NewPipeFactory(),
cfg,
)
+ assert.NoError(t, err)
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
res, err := p.Exec(&Payload{Body: []byte("hello")})
@@ -192,7 +196,10 @@ func Test_StaticPool_Broken_FromOutside(t *testing.T) {
// killing random worker and expecting pool to replace it
p.muw.Lock()
- p.workers[0].cmd.Process.Kill()
+ err = p.Workers()[0].cmd.Process.Kill()
+ if err != nil {
+ t.Errorf("error killing the process: error %v", err)
+ }
p.muw.Unlock()
<-destructed
@@ -244,10 +251,10 @@ func Test_StaticPool_Replace_Worker(t *testing.T) {
DestroyTimeout: time.Second,
},
)
+ assert.NoError(t, err)
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
var lastPID string
lastPID = strconv.Itoa(*p.Workers()[0].Pid)
@@ -279,10 +286,10 @@ func Test_StaticPool_Stop_Worker(t *testing.T) {
DestroyTimeout: time.Second,
},
)
+ assert.NoError(t, err)
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
var lastPID string
lastPID = strconv.Itoa(*p.Workers()[0].Pid)
@@ -357,10 +364,10 @@ func Test_Static_Pool_Handle_Dead(t *testing.T) {
DestroyTimeout: time.Second,
},
)
+ assert.NoError(t, err)
defer p.Destroy()
assert.NotNil(t, p)
- assert.NoError(t, err)
for _, w := range p.workers {
w.state.value = StateErrored
diff --git a/worker.go b/worker.go
index a95a80b3..6be841a9 100644
--- a/worker.go
+++ b/worker.go
@@ -105,7 +105,10 @@ func (w *Worker) Wait() error {
if runtime.GOOS != "windows" {
// windows handles processes and close pipes differently,
// we can ignore wait here as process.Wait() already being handled above
- w.cmd.Wait()
+ err := w.cmd.Wait()
+ if err != nil {
+ return err
+ }
}
if w.endState.Success() {
@@ -214,10 +217,16 @@ func (w *Worker) start() error {
defer w.mu.Unlock()
if w.rl != nil {
- w.rl.Close()
+ err := w.rl.Close()
+ if err != nil {
+ w.err.lsn(EventWorkerError, WorkerError{Worker: w, Caused: err})
+ }
}
- w.err.Close()
+ err := w.err.Close()
+ if err != nil {
+ w.err.lsn(EventWorkerError, WorkerError{Worker: w, Caused: err})
+ }
}
}()