You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not an issue that needs to be addressed right now, but it can be quite nice for things like this is to allow the iterations to vary based on the -short flag. For example:
funcNumTrials() {
iftesting.Short() {
return16
}
return1<<8// or more
}
If you want to get even more fancy, something I've done before is to also define custom -long and -stress flags. So you can do:
// Custom test command line flags.var (
long=flag.Bool("long", false, "enable long running tests")
stress=flag.Bool("stress", false, "enable stress tests (implies -long)")
)
// timeallowed returns how long a single test is allowed to take.functimeallowed() time.Duration {
switch {
casetesting.Short():
returntime.Second/10case*long:
return30*time.Secondcase*stress:
return2*time.Minutedefault:
returntime.Second
}
}
// Repeat the given trial function. The duration is controlled by custom// command-line flags. The trial function returns whether it wants to continue// testing.//// -short run for less time than usual// -long allow more time// -stress run for an extremely long timefuncRepeat(t*testing.T, trialfunc(t*testing.T) bool) {
start:=time.Now()
d:=timeallowed()
n:=1fortime.Since(start) <d&&trial(t) {
n++
}
t.Logf("%d trials in %s", n, time.Since(start))
}
I usually put something like this in an internal/test package. Then you wrap your test in a test.Repeat(...) call and it will run until the time limit.
Not an issue that needs to be addressed right now, but it can be quite nice for things like this is to allow the iterations to vary based on the
-short
flag. For example:If you want to get even more fancy, something I've done before is to also define custom
-long
and-stress
flags. So you can do:I usually put something like this in an
internal/test
package. Then you wrap your test in atest.Repeat(...)
call and it will run until the time limit.Originally posted by @mmcloughlin in #102
The text was updated successfully, but these errors were encountered: