Skip to content

Commit

Permalink
fix: lint issue
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Fu <weifu@microsoft.com>
  • Loading branch information
fuweid committed Dec 7, 2023
1 parent 6bbdc59 commit 82e36b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
22 changes: 11 additions & 11 deletions request/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ type WeightedRandomRequests struct {
wg sync.WaitGroup
ctx context.Context
cancel context.CancelFunc
reqBuilderCh chan RequestBuilder
reqBuilderCh chan RESTRequestBuilder

shares []int
reqBuilders []RequestBuilder
reqBuilders []RESTRequestBuilder
}

// NewWeightedRandomRequests creates new instance of WeightedRandomRequests.
Expand All @@ -34,11 +34,11 @@ func NewWeightedRandomRequests(spec *types.LoadProfileSpec) (*WeightedRandomRequ
}

shares := make([]int, 0, len(spec.Requests))
reqBuilders := make([]RequestBuilder, 0, len(spec.Requests))
reqBuilders := make([]RESTRequestBuilder, 0, len(spec.Requests))
for _, r := range spec.Requests {
shares = append(shares, r.Shares)

var builder RequestBuilder
var builder RESTRequestBuilder
switch {
case r.StaleList != nil:
builder = newRequestListBuilder(r.StaleList, "0")
Expand All @@ -49,7 +49,7 @@ func NewWeightedRandomRequests(spec *types.LoadProfileSpec) (*WeightedRandomRequ
case r.QuorumGet != nil:
builder = newRequestGetBuilder(r.QuorumGet, "")
default:
return nil, fmt.Errorf("only support get/list")
return nil, fmt.Errorf("not implement for PUT yet")
}
reqBuilders = append(reqBuilders, builder)
}
Expand All @@ -58,7 +58,7 @@ func NewWeightedRandomRequests(spec *types.LoadProfileSpec) (*WeightedRandomRequ
return &WeightedRandomRequests{
ctx: ctx,
cancel: cancel,
reqBuilderCh: make(chan RequestBuilder),
reqBuilderCh: make(chan RESTRequestBuilder),
shares: shares,
reqBuilders: reqBuilders,
}, nil
Expand All @@ -74,7 +74,7 @@ func (r *WeightedRandomRequests) Run(ctx context.Context, total int) {
builder := r.randomPick()
select {
case r.reqBuilderCh <- builder:
sum += 1
sum++
case <-r.ctx.Done():
return
case <-ctx.Done():
Expand All @@ -84,11 +84,11 @@ func (r *WeightedRandomRequests) Run(ctx context.Context, total int) {
}

// Chan returns channel to get random request.
func (r *WeightedRandomRequests) Chan() chan RequestBuilder {
func (r *WeightedRandomRequests) Chan() chan RESTRequestBuilder {
return r.reqBuilderCh
}

func (r *WeightedRandomRequests) randomPick() RequestBuilder {
func (r *WeightedRandomRequests) randomPick() RESTRequestBuilder {
sum := 0
for _, s := range r.shares {
sum += s
Expand Down Expand Up @@ -119,8 +119,8 @@ func (r *WeightedRandomRequests) Stop() {
})
}

// RequestBuilder is used to build rest.Request.
type RequestBuilder interface {
// RESTRequestBuilder is used to build rest.Request.
type RESTRequestBuilder interface {
Build(cli rest.Interface) (method string, _ *rest.Request)
}

Expand Down
1 change: 1 addition & 0 deletions request/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const defaultTimeout = 60 * time.Second
// Schedule files requests to apiserver based on LoadProfileSpec.
func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.Interface) (*types.ResponseStats, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

rndReqs, err := NewWeightedRandomRequests(spec)
if err != nil {
Expand Down

0 comments on commit 82e36b2

Please sign in to comment.