func()

in cmd/core/runner/concurrency.go [39:88]


func (r *ConcurrencyRunner) Before(workers tester.Workers, opts interface{}) error {
	if err := r.runner.Before(workers, opts); err != nil {
		return err
	}

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

	r.workerSem = bender.NewWorkerSemaphore()

	go func() { r.workerSem.Signal(workers) }()

	r.requests = make(chan interface{})

	ctx, cancel := context.WithCancel(context.Background())

	go func() {
		for i := 0; ; i++ {
			select {
			case <-ctx.Done():
				close(r.requests)

				return
			default:
				r.requests <- r.Params.RequestGenerator(i)
			}
		}
	}()

	// We want tne progressbar to measure the time passed.
	const scale = 10
	count := int(o.Duration/time.Second) * scale

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

	go func() {
		for i := 0; i < count; i++ {
			time.Sleep(time.Second / scale)
			r.bar.Incr()
		}
		cancel()
		r.progress.Stop()
		r.spinnerCancel = utils.NewBackgroundSpinner("Waiting for tests to finish", 0)
	}()

	return nil
}