| 1 |
package dnsfuzz |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"testing" |
| 6 |
"time" |
| 7 |
) |
| 8 |
|
| 9 |
// Stop returns true when the fuzz test should stop. If gets the duration from the environment variable FUZZ |
| 10 |
// which should contain a Go duration string like '20m', or '10h'. If FUZZ is empty or can't be found true is |
| 11 |
// returned. |
| 12 |
func Stop(t *testing.T, start time.Time) bool { |
| 13 |
fuzz := os.Getenv("FUZZ") |
| 14 |
if fuzz == "" { |
| 15 |
return true |
| 16 |
} |
| 17 |
d, err := time.ParseDuration(fuzz) |
| 18 |
if err != nil { |
| 19 |
return false |
| 20 |
} |
| 21 |
ok := time.Since(start) > d |
| 22 |
if ok { |
| 23 |
t.Logf("Stopping fuzzing after: %s", d) |
| 24 |
t.FailNow() |
| 25 |
} |
| 26 |
return ok |
| 27 |
} |