Skip to content

Commit

Permalink
Flags for setting poll timeout and poll interval (knative-extensions#630
Browse files Browse the repository at this point in the history
)

* Flags for setting poll timeout and poll interval

* Rebase on latest changes when timings were moved to state package

* Move setting default pollInterval and pollTimeout before applying opts
  • Loading branch information
mgencur committed Nov 21, 2023
1 parent c0729ef commit 6055c2d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/environment/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"fmt"
"strconv"
"strings"
"time"

"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/state"
)

var (
Expand All @@ -34,6 +36,9 @@ var (

ipFilePath = new(string)
teardownOnFail = new(bool)

pollTimeout = new(time.Duration)
pollInterval = new(time.Duration)
)

// InitFlags registers the requirement and state filter flags supported by the
Expand Down Expand Up @@ -62,7 +67,8 @@ func InitFlags(fs *flag.FlagSet) {

fs.StringVar(ipFilePath, "images.producer.file", "", "file path for file-based image producer")
fs.StringVar(testNamespace, "environment.namespace", "", "Test namespace")

fs.DurationVar(pollTimeout, "poll.timeout", state.DefaultPollTimeout, "Poll timeout")
fs.DurationVar(pollInterval, "poll.interval", state.DefaultPollInterval, "Poll interval")
fs.BoolVar(teardownOnFail, "teardown.on.fail", false, "Set this flag to do teardown even if test fails.")
}

Expand Down
1 change: 1 addition & 0 deletions pkg/environment/magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (mr *MagicGlobalEnvironment) Environment(opts ...EnvOpts) (context.Context,
}

ctx := ContextWith(mr.c, env)
ctx = ContextWithPollTimings(ctx, *pollInterval, *pollTimeout)

for _, opt := range opts {
if nctx, err := opt(ctx, env); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/timings.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ func PollTimingsFromContext(ctx context.Context) (time.Duration, time.Duration)
if t, ok := ctx.Value(timingsKey{}).(timingsType); ok {
return t.interval, t.timeout
}
return DefaultPollInterval, DefaultPollTimeout
panic("no poll timings found in context")
}

0 comments on commit 6055c2d

Please sign in to comment.