summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-10 15:33:08 +0300
committerWolfy-J <[email protected]>2018-09-10 15:33:08 +0300
commit9573091c7f0603c1d52a1180852d359feff7d99d (patch)
tree1030fd195fc2eba1e9a82138cab2ac1f58bab473
parente455a2446016973065fa5dbf24c453d0427f7709 (diff)
more tests
-rw-r--r--service/http/handler_test.go58
-rw-r--r--service/http/rpc.go4
2 files changed, 60 insertions, 2 deletions
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index 59a4c7c0..b82fc938 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -14,6 +14,7 @@ import (
"strings"
"testing"
"time"
+ "net/http/httptest"
)
// get request and return body
@@ -63,6 +64,63 @@ func TestServer_Echo(t *testing.T) {
assert.Equal(t, "WORLD", body)
}
+func Test_HandlerErrors(t *testing.T) {
+ st := &Handler{
+ cfg: &Config{
+ MaxRequest: 1024,
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{},
+ },
+ },
+ rr: roadrunner.NewServer(&roadrunner.ServerConfig{
+ Command: "php ../../php-src/tests/http/client.php echo pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 1,
+ AllocateTimeout: 10000000,
+ DestroyTimeout: 10000000,
+ },
+ }),
+ }
+
+ wr := httptest.NewRecorder()
+ rq := httptest.NewRequest("POST", "/", bytes.NewBuffer([]byte("data")))
+
+ st.ServeHTTP(wr, rq)
+ assert.Equal(t, 500, wr.Code)
+}
+
+func Test_Handler_JSON_error(t *testing.T) {
+ st := &Handler{
+ cfg: &Config{
+ MaxRequest: 1024,
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{},
+ },
+ },
+ rr: roadrunner.NewServer(&roadrunner.ServerConfig{
+ Command: "php ../../php-src/tests/http/client.php echo pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 1,
+ AllocateTimeout: 10000000,
+ DestroyTimeout: 10000000,
+ },
+ }),
+ }
+
+ wr := httptest.NewRecorder()
+ rq := httptest.NewRequest("POST", "/", bytes.NewBuffer([]byte("{sd")))
+ rq.Header.Add("Content-Type","application/json")
+ rq.Header.Add("Content-Size","3")
+
+ st.ServeHTTP(wr, rq)
+ assert.Equal(t, 500, wr.Code)
+}
+
+
func TestServer_Headers(t *testing.T) {
st := &Handler{
cfg: &Config{
diff --git a/service/http/rpc.go b/service/http/rpc.go
index aebc5903..9dfe718e 100644
--- a/service/http/rpc.go
+++ b/service/http/rpc.go
@@ -29,7 +29,7 @@ type Worker struct {
// Reset resets underlying RR worker pool and restarts all of it's workers.
func (rpc *rpcServer) Reset(reset bool, r *string) error {
- if rpc.svc.srv == nil {
+ if rpc.svc == nil || rpc.svc.srv == nil {
return errors.New("http server is not running")
}
@@ -39,7 +39,7 @@ func (rpc *rpcServer) Reset(reset bool, r *string) error {
// Workers returns list of active workers and their stats.
func (rpc *rpcServer) Workers(list bool, r *WorkerList) error {
- if rpc.svc.srv == nil {
+ if rpc.svc == nil || rpc.svc.srv == nil {
return errors.New("http server is not running")
}