Susumu Yata
null+****@clear*****
Fri Jul 28 15:31:59 JST 2017
Susumu Yata 2017-07-28 15:31:59 +0900 (Fri, 28 Jul 2017) New Revision: 1fd7ab2984ab491b2061d486e67808f10add0595 https://github.com/groonga/grnci/commit/1fd7ab2984ab491b2061d486e67808f10add0595 Message: Add benchmarks for various clients. Modified files: v2/gqtp_test.go v2/http_test.go v2/libgrn/client_test.go Modified: v2/gqtp_test.go (+31 -0) =================================================================== --- v2/gqtp_test.go 2017-07-28 15:04:42 +0900 (efd6961) +++ v2/gqtp_test.go 2017-07-28 15:31:59 +0900 (8b8f178) @@ -130,6 +130,37 @@ func TestGQTPClient(t *testing.T) { } } +func BenchmarkGQTPClient(b *testing.B) { + server := newGQTPServer(b) + defer server.Close() + + client, err := NewGQTPClient("", nil) + if err != nil { + b.Skipf("NewGQTPClient failed: %v", err) + } + defer client.Close() + + for i := 0; i < b.N; i++ { + resp, err := client.Exec("status", nil) + if err != nil { + b.Fatalf("conn.Exec failed: err = %v", err) + } + respBody, err := ioutil.ReadAll(resp) + if err != nil { + b.Fatalf("ioutil.ReadAll failed: err = %v", err) + } + if err := resp.Err(); err != nil { + b.Fatalf("client.Exec failed: err = %v", err) + } + if len(respBody) == 0 { + b.Fatalf("ioutil.ReadAll failed: len(respBody) = 0") + } + if err := resp.Close(); err != nil { + b.Fatalf("resp.Close failed: %v", err) + } + } +} + func TestGQTPClientHandler(t *testing.T) { var i interface{} = &GQTPClient{} if _, ok := i.(Handler); !ok { Modified: v2/http_test.go (+30 -0) =================================================================== --- v2/http_test.go 2017-07-28 15:04:42 +0900 (25035a4) +++ v2/http_test.go 2017-07-28 15:31:59 +0900 (9d25a74) @@ -130,6 +130,36 @@ func TestHTTPClient(t *testing.T) { } } +func BenchmarkHTTPClient(b *testing.B) { + server := newHTTPServer(b) + defer server.Close() + + client, err := NewHTTPClient("", nil) + if err != nil { + b.Skipf("NewHTTPClient failed: %v", err) + } + defer client.Close() + + for i := 0; i < b.N; i++ { + resp, err := client.Exec("status", nil) + if err != nil { + b.Fatalf("conn.Exec failed: err = %v", err) + } + respBody, err := ioutil.ReadAll(resp) + if err != nil { + b.Fatalf("ioutil.ReadAll failed: err = %v", err) + } + if err := resp.Err(); err != nil { + b.Fatalf("client.Exec failed: err = %v", err) + } + if len(respBody) == 0 { + b.Fatalf("ioutil.ReadAll failed: len(respBody) = 0") + } + if err := resp.Close(); err != nil { + b.Fatalf("resp.Close failed: %v", err) + } + } +} func TestHTTPClientHandler(t *testing.T) { var i interface{} = &HTTPClient{} if _, ok := i.(Handler); !ok { Modified: v2/libgrn/client_test.go (+64 -0) =================================================================== --- v2/libgrn/client_test.go 2017-07-28 15:04:42 +0900 (c8d25c2) +++ v2/libgrn/client_test.go 2017-07-28 15:31:59 +0900 (4beac6a) @@ -207,6 +207,70 @@ func TestDBClient(t *testing.T) { } } +func BenchmarkGQTPClient(b *testing.B) { + server := newGQTPServer(b) + defer server.Close() + + client, err := Dial("", nil) + if err != nil { + b.Skipf("Dial failed: %v", err) + } + defer client.Close() + + for i := 0; i < b.N; i++ { + resp, err := client.Exec("status", nil) + if err != nil { + b.Fatalf("conn.Exec failed: err = %v", err) + } + respBody, err := ioutil.ReadAll(resp) + if err != nil { + b.Fatalf("ioutil.ReadAll failed: err = %v", err) + } + if err := resp.Err(); err != nil { + b.Fatalf("client.Exec failed: err = %v", err) + } + if len(respBody) == 0 { + b.Fatalf("ioutil.ReadAll failed: len(respBody) = 0") + } + if err := resp.Close(); err != nil { + b.Fatalf("resp.Close failed: %v", err) + } + } +} + +func BenchmarkDBClient(b *testing.B) { + dir, err := ioutil.TempDir("", "grnci") + if err != nil { + b.Fatalf("ioutil.TempDir failed: %v", err) + } + defer os.RemoveAll(dir) + + client, err := Create(filepath.Join(dir, "db"), nil) + if err != nil { + b.Skipf("Dial failed: %v", err) + } + defer client.Close() + for i := 0; i < b.N; i++ { + resp, err := client.Exec("status", nil) + if err != nil { + b.Fatalf("conn.Exec failed: err = %v", err) + } + respBody, err := ioutil.ReadAll(resp) + if err != nil { + b.Fatalf("ioutil.ReadAll failed: err = %v", err) + } + if err := resp.Err(); err != nil { + b.Fatalf("client.Exec failed: err = %v", err) + } + if len(respBody) == 0 { + b.Fatalf("ioutil.ReadAll failed: len(respBody) = 0") + } + if err := resp.Close(); err != nil { + b.Fatalf("resp.Close failed: %v", err) + } + } +} + func TestClientHandler(t *testing.T) { var i interface{} = &Client{} if _, ok := i.(grnci.Handler); !ok { -------------- next part -------------- HTML����������������������������... Télécharger