From 9c8492efb97dab916f41884ea2a1eed3b39a2d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 25 Aug 2022 09:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/rpc/rpc_client_test.go | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/internal/rpc/rpc_client_test.go b/internal/rpc/rpc_client_test.go index d0cb2361..0c1076a6 100644 --- a/internal/rpc/rpc_client_test.go +++ b/internal/rpc/rpc_client_test.go @@ -35,7 +35,8 @@ func TestRPCClient_NodeRPC(t *testing.T) { func TestRPC_Dial_HTTP(t *testing.T) { client, err := NewRPCClient(&configs.APIConfig{ RPC: struct { - Endpoints []string `yaml:"endpoints"` + Endpoints []string `yaml:"endpoints"` + DisableUpdate bool `yaml:"disableUpdate"` }{ Endpoints: []string{"http://127.0.0.1:8004"}, }, @@ -56,7 +57,8 @@ func TestRPC_Dial_HTTP(t *testing.T) { func TestRPC_Dial_HTTP_2(t *testing.T) { client, err := NewRPCClient(&configs.APIConfig{ RPC: struct { - Endpoints []string `yaml:"endpoints"` + Endpoints []string `yaml:"endpoints"` + DisableUpdate bool `yaml:"disableUpdate"` }{ Endpoints: []string{"https://127.0.0.1:8003"}, }, @@ -77,7 +79,8 @@ func TestRPC_Dial_HTTP_2(t *testing.T) { func TestRPC_Dial_HTTPS(t *testing.T) { client, err := NewRPCClient(&configs.APIConfig{ RPC: struct { - Endpoints []string `yaml:"endpoints"` + Endpoints []string `yaml:"endpoints"` + DisableUpdate bool `yaml:"disableUpdate"` }{ Endpoints: []string{"https://127.0.0.1:8004"}, }, @@ -94,3 +97,53 @@ func TestRPC_Dial_HTTPS(t *testing.T) { } t.Log(resp.Node) } + +func BenchmarkNewRPCClient(b *testing.B) { + config, err := configs.LoadAPIConfig() + if err != nil { + b.Fatal(err) + } + rpc, err := NewRPCClient(config, true) + if err != nil { + b.Fatal(err) + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + resp, err := rpc.AdminRPC().LoginAdmin(rpc.Context(0), &pb.LoginAdminRequest{ + Username: "admin", + Password: stringutil.Md5("123456"), + }) + if err != nil { + b.Fatal(err) + } + _ = resp + } +} + +func BenchmarkNewRPCClient_2(b *testing.B) { + config, err := configs.LoadAPIConfig() + if err != nil { + b.Fatal(err) + } + rpc, err := NewRPCClient(config, true) + if err != nil { + b.Fatal(err) + } + + var conn = rpc.AdminRPC() + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + resp, err := conn.LoginAdmin(rpc.Context(0), &pb.LoginAdminRequest{ + Username: "admin", + Password: stringutil.Md5("123456"), + }) + if err != nil { + b.Fatal(err) + } + _ = resp + } +}