Skip to content

Commit 33fe17c

Browse files
added pre-delay to looper creation (#771)
1 parent a0e7b5a commit 33fe17c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmd/zrok/testCanaryPeriodic.go

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/openziti/zrok/environment"
66
"github.com/sirupsen/logrus"
77
"github.com/spf13/cobra"
8+
"math/rand"
89
"os"
910
"os/signal"
1011
"syscall"
@@ -23,6 +24,8 @@ type testCanaryPeriodicCommand struct {
2324
timeout time.Duration
2425
minPayload uint64
2526
maxPayload uint64
27+
minPreDelay time.Duration
28+
maxPreDelay time.Duration
2629
minDwell time.Duration
2730
maxDwell time.Duration
2831
minPacing time.Duration
@@ -44,6 +47,8 @@ func newTestCanaryPeriodicCommand() *testCanaryPeriodicCommand {
4447
cmd.Flags().DurationVarP(&command.timeout, "timeout", "T", 30*time.Second, "Timeout when sending HTTP requests")
4548
cmd.Flags().Uint64Var(&command.minPayload, "min-payload", 64, "Minimum payload size in bytes")
4649
cmd.Flags().Uint64Var(&command.maxPayload, "max-payload", 10240, "Maximum payload size in bytes")
50+
cmd.Flags().DurationVar(&command.minPreDelay, "min-pre-delay", 0, "Minimum pre-delay before creating the next looper")
51+
cmd.Flags().DurationVar(&command.maxPreDelay, "max-pre-delay", 0, "Maximum pre-delay before creating the next looper")
4752
cmd.Flags().DurationVar(&command.minDwell, "min-dwell", 1*time.Second, "Minimum dwell time")
4853
cmd.Flags().DurationVar(&command.maxDwell, "max-dwell", 1*time.Second, "Maximum dwell time")
4954
cmd.Flags().DurationVar(&command.minPacing, "min-pacing", 0, "Minimum pacing time")
@@ -64,6 +69,13 @@ func (cmd *testCanaryPeriodicCommand) run(_ *cobra.Command, _ []string) {
6469

6570
var loopers []*canary.PublicHttpLooper
6671
for i := uint(0); i < cmd.loopers; i++ {
72+
preDelay := cmd.maxPreDelay.Milliseconds()
73+
preDelayDelta := cmd.maxPreDelay.Milliseconds() - cmd.minPreDelay.Milliseconds()
74+
if preDelayDelta > 0 {
75+
preDelay = int64(rand.Intn(int(preDelayDelta))) + cmd.minPreDelay.Milliseconds()
76+
time.Sleep(time.Duration(preDelay) * time.Millisecond)
77+
}
78+
6779
looperOpts := &canary.LooperOptions{
6880
Iterations: cmd.iterations,
6981
StatusInterval: cmd.statusInterval,

0 commit comments

Comments
 (0)