This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: enable setting poll timeout and step duration (#154)
In some circumstances, we need to adjust the step and timeout duration of the polling we do during e2e tests. This hooks them up to the E2E_POLL_STEP_DURATION and E2E_POLL_TIMEOUT environment variables. These environment variables accept values similar to the `--timeout` parameter of `kubectl wait`. For instance, to set a timeout of five minutes for polling timeouts, we set `E2E_POLL_TIMEOUT=5m`. By default, polling timeouts after 1 minute, and steps are run every second. Signed-off-by: Andy Sadler <ansadler@redhat.com>
- Loading branch information
Showing
5 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package poll | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
const envE2EPollTimeout = "E2E_POLL_TIMEOUT" | ||
const envE2EPollStepDuration = "E2E_POLL_STEP_DURATION" | ||
|
||
func init() { | ||
pollTimeout = max(getDurationFromEnv(envE2EPollTimeout, time.Minute), 10*time.Second) | ||
pollStepDuration = max(getDurationFromEnv(envE2EPollStepDuration, time.Second), time.Second) | ||
if pollTimeout < pollStepDuration { | ||
panic(fmt.Sprintf("Poll timeout (%v) longer than step duration (%v)", pollTimeout, pollStepDuration)) | ||
} | ||
} | ||
|
||
var pollTimeout time.Duration | ||
var pollStepDuration time.Duration | ||
|
||
func getDurationFromEnv(envVar string, defaultDuration time.Duration) time.Duration { | ||
value := os.Getenv(envVar) | ||
duration, err := time.ParseDuration(value) | ||
if err != nil { | ||
duration = defaultDuration | ||
} | ||
return duration | ||
} | ||
|
||
// WaitForConditionImmediately runs the function `condition` periodically to poll the | ||
// status of a condition. It waits for either condition's first return value | ||
// to be `true`, or for a timeout to be hit. | ||
// | ||
// By default, this timeout is 1 minute, and `condition` is checked every | ||
// second. These can be overridden with the `E2E_POLL_TIMEOUT` and | ||
// `E2E_POLL_STEP_DURATION` environment variables. | ||
func WaitForConditionImmediately(ctx context.Context, condition func(ctx context.Context) (bool, error)) error { | ||
return wait.PollUntilContextTimeout(ctx, pollStepDuration, pollTimeout, true, condition) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters