summaryrefslogtreecommitdiff
path: root/service/http/handler_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-13 22:01:23 +0300
committerWolfy-J <[email protected]>2018-06-13 22:01:23 +0300
commit51098a18ac6d96c0a134976c0e51b09c1679078c (patch)
tree89a2811c2de903f127b712366ec71feba8a83f32 /service/http/handler_test.go
parent5da779709722263f49d1d9e84b4e1aa2dfc07929 (diff)
middleware
Diffstat (limited to 'service/http/handler_test.go')
-rw-r--r--service/http/handler_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index 98379117..d121ba76 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -13,6 +13,7 @@ import (
"bytes"
"mime/multipart"
"time"
+ "runtime"
)
// get request and return body
@@ -661,3 +662,47 @@ func TestServer_Multipart_PATCH(t *testing.T) {
assert.Equal(t, `{"arr":{"c":{"p":"l","z":""},"x":{"y":{"e":"f","z":"y"}}},"key":"value","name":["name1","name2","name3"]}`, string(b))
}
+
+func BenchServer_Echo(b *testing.B) {
+ 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: int64(runtime.NumCPU()),
+ AllocateTimeout: 10000000,
+ DestroyTimeout: 10000000,
+ },
+ }),
+ }
+
+ st.rr.Start()
+ defer st.rr.Stop()
+
+ hs := &http.Server{Addr: ":8077", Handler: st}
+ defer hs.Shutdown(context.Background())
+
+ go func() { hs.ListenAndServe() }()
+ time.Sleep(time.Millisecond * 10)
+
+ bb := "WORLD"
+ for n := 0; n < b.N; n++ {
+ r, err := http.Get("http://localhost:8077/?hello=world")
+ if err != nil {
+ b.Fail()
+ }
+ defer r.Body.Close()
+
+ br, _ := ioutil.ReadAll(r.Body)
+ if string(br) != bb {
+ b.Fail()
+ }
+ }
+}