From 51098a18ac6d96c0a134976c0e51b09c1679078c Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Wed, 13 Jun 2018 22:01:23 +0300 Subject: middleware --- service/http/handler_test.go | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'service/http/handler_test.go') 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() + } + } +} -- cgit v1.2.3