Skip to content

Commit

Permalink
♻️ Refactor loadtest usecase New func
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
  • Loading branch information
rinx committed Jun 9, 2020
1 parent da2ba56 commit 31a478a
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions pkg/tools/cli/loadtest/usecase/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,39 @@ import (

type run struct {
eg errgroup.Group
cfg *config.Data
loader service.Loader
client grpc.Client
}

// 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)
}

Expand Down

0 comments on commit 31a478a

Please sign in to comment.