-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support slowing down tests to enable debugging consequences
This change introduces a supported environment variable called `JUSTEST_SLOW_FACTOR` which, when set to an integer value, will cause Justest to multiple durations passed to the `For(...)` and `Within(...)` methods with its value. This will cause these duration to be longer, thus allowing the developer to investigate or debug side consequences of such tests - like logging into clusters and checking the effects of end-to-end tests, inspecting file-systems, etc.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 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,21 @@ | ||
package justest | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func transformDurationIfNecessary(t T, d time.Duration) time.Duration { | ||
if v, found := os.LookupEnv(SlowFactorEnvVarName); found { | ||
if factor, err := strconv.ParseInt(v, 0, 0); err != nil { | ||
t.Logf("Ignoring value of '%s' environment variable: %+v", SlowFactorEnvVarName, err) | ||
return d | ||
} else { | ||
oldSeconds := int64(d.Seconds()) | ||
newSeconds := oldSeconds * factor | ||
return time.Duration(newSeconds) * time.Second | ||
} | ||
} | ||
return d | ||
} |
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,14 @@ | ||
package justest | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTransformDurationIfNecessary(t *testing.T) { | ||
With(t).Verify(transformDurationIfNecessary(t, 5*time.Second)).Will(EqualTo(5 * time.Second)).OrFail() | ||
t.Setenv(SlowFactorEnvVarName, "2") | ||
With(t).Verify(transformDurationIfNecessary(t, 5*time.Second)).Will(EqualTo(10 * time.Second)).OrFail() | ||
t.Setenv(SlowFactorEnvVarName, "3") | ||
With(t).Verify(transformDurationIfNecessary(t, 5*time.Second)).Will(EqualTo(15 * time.Second)).OrFail() | ||
} |