in internal/soaktest/runner.go [118:156]
func (runner *Runner) Run(ctx context.Context) error {
if runner.config.RunDuration != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)
go func() {
select {
case <-ctx.Done():
case <-time.After(runner.config.RunDuration):
}
cancel()
}()
}
g, gCtx := errgroup.WithContext(ctx)
// Create a Rand with the same seed for each agent, so we randomise their IDs consistently.
var rngseed int64
err := binary.Read(cryptorand.Reader, binary.LittleEndian, &rngseed)
if err != nil {
return fmt.Errorf("failed to generate seed for math/rand: %w", err)
}
runner.logger.Info("running scenario `" + runner.scenarioName + "`...")
for _, config := range runner.scenarioConfigs {
config := config
// when not specified, default to 1
if config.AgentReplicas <= 0 {
config.AgentReplicas = 1
}
for i := 0; i < config.AgentReplicas; i++ {
runner.logger.Debug(fmt.Sprintf("agent: %s, replica %d, event-rate: %s", config.AgentName, i, config.EventRate))
g.Go(func() error {
rng := rand.New(rand.NewSource(rngseed))
return runAgent(gCtx, runner, config, rng)
})
}
}
return g.Wait()
}