From da2ba56fb6bcfcddbe2be7f67d3aa85a1f4303eb Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Tue, 9 Jun 2020 17:10:35 +0900 Subject: [PATCH 1/3] :bug: Add WithOperation func to loadtest usecase Signed-off-by: Rintaro Okamura --- pkg/tools/cli/loadtest/usecase/load.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/tools/cli/loadtest/usecase/load.go b/pkg/tools/cli/loadtest/usecase/load.go index 5fcdc2c126..4261c0ead4 100644 --- a/pkg/tools/cli/loadtest/usecase/load.go +++ b/pkg/tools/cli/loadtest/usecase/load.go @@ -55,6 +55,7 @@ func (r *run) PreStart(ctx context.Context) (err error) { ) opts := []service.Option{ + service.WithOperation(r.cfg.Method), service.WithAddr(r.cfg.Addr), service.WithDataset(r.cfg.Dataset), service.WithClient(r.client), From 31a478a9310c0edfb69cd93be9c19fceaa4ea30e Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Tue, 9 Jun 2020 17:30:13 +0900 Subject: [PATCH 2/3] :recycle: Refactor loadtest usecase New func Signed-off-by: Rintaro Okamura --- pkg/tools/cli/loadtest/usecase/load.go | 42 ++++++++++++-------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/pkg/tools/cli/loadtest/usecase/load.go b/pkg/tools/cli/loadtest/usecase/load.go index 4261c0ead4..f8a4bef011 100644 --- a/pkg/tools/cli/loadtest/usecase/load.go +++ b/pkg/tools/cli/loadtest/usecase/load.go @@ -31,7 +31,6 @@ import ( type run struct { eg errgroup.Group - cfg *config.Data loader service.Loader client grpc.Client } @@ -39,35 +38,32 @@ type run struct { // New returns Runner instance. func New(cfg *config.Data) (r runner.Runner, err error) { run := &run{ - cfg: cfg, - eg: errgroup.Get(), + eg: errgroup.Get(), } - return run, nil -} - -// PreStart initializes load tester and returns error if occurred. -func (r *run) PreStart(ctx context.Context) (err error) { - r.client = grpc.New( - grpc.WithAddrs(append([]string{r.cfg.Addr}, r.cfg.Client.Addrs...)...), - grpc.WithInsecure(r.cfg.Client.DialOption.Insecure), - grpc.WithErrGroup(r.eg), + run.client = grpc.New( + grpc.WithAddrs(append([]string{cfg.Addr}, cfg.Client.Addrs...)...), + grpc.WithInsecure(cfg.Client.DialOption.Insecure), + grpc.WithErrGroup(run.eg), ) - opts := []service.Option{ - service.WithOperation(r.cfg.Method), - service.WithAddr(r.cfg.Addr), - service.WithDataset(r.cfg.Dataset), - service.WithClient(r.client), - service.WithConcurrency(r.cfg.Concurrency), - service.WithProgressDuration(r.cfg.ProgressDuration), - } - - r.loader, err = service.NewLoader(opts...) + run.loader, err = service.NewLoader( + service.WithOperation(cfg.Method), + service.WithAddr(cfg.Addr), + service.WithDataset(cfg.Dataset), + service.WithClient(run.client), + service.WithConcurrency(cfg.Concurrency), + service.WithProgressDuration(cfg.ProgressDuration), + ) if err != nil { - return err + return nil, err } + return run, nil +} + +// PreStart initializes load tester and returns error if occurred. +func (r *run) PreStart(ctx context.Context) (err error) { return r.loader.Prepare(ctx) } From f89fc3790043edf1e380a4b88ed4f82f2b32f63b Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Tue, 9 Jun 2020 17:41:11 +0900 Subject: [PATCH 3/3] :recycle: Use GRPCClient.Opts func Signed-off-by: Rintaro Okamura --- pkg/tools/cli/loadtest/usecase/load.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/tools/cli/loadtest/usecase/load.go b/pkg/tools/cli/loadtest/usecase/load.go index f8a4bef011..7f78fb3d25 100644 --- a/pkg/tools/cli/loadtest/usecase/load.go +++ b/pkg/tools/cli/loadtest/usecase/load.go @@ -41,11 +41,12 @@ func New(cfg *config.Data) (r runner.Runner, err error) { eg: errgroup.Get(), } - run.client = grpc.New( - grpc.WithAddrs(append([]string{cfg.Addr}, cfg.Client.Addrs...)...), - grpc.WithInsecure(cfg.Client.DialOption.Insecure), + clientOpts := append( + cfg.Client.Opts(), + grpc.WithAddrs(cfg.Addr), grpc.WithErrGroup(run.eg), ) + run.client = grpc.New(clientOpts...) run.loader, err = service.NewLoader( service.WithOperation(cfg.Method),