func()

in cmd/core/runner/throughput.go [36:63]


func (r *ThroughputRunner) Before(qps tester.QPS, opts interface{}) error {
	if err := r.runner.Before(qps, opts); err != nil {
		return err
	}

	o, ok := opts.(*options.Options)
	if !ok {
		return tester.ErrInvalidOptions
	}

	count := int(float64(qps) * float64(o.Duration/time.Second))
	r.intervals = o.Distribution(float64(qps))

	r.requests = make(chan interface{}, o.BufferSize)

	go func() {
		for i := 0; i < count; i++ {
			r.requests <- r.Params.RequestGenerator(i)
		}
		close(r.requests)
	}()

	r.progress, r.bar = recorders.NewLoadTestProgress(count)
	r.progress.Start()
	r.recorders = append(r.recorders, recorders.NewProgressBarRecorder(r.bar))

	return nil
}