...
1[!fuzz] skip
2[short] skip
3env GOCACHE=$WORK/cache
4
5# The fuzz function should be able to detect whether -timeout
6# was set with T.Deadline. Note there is no F.Deadline, and
7# there is no timeout while fuzzing, even if -fuzztime is set.
8go test -run=FuzzDeadline -wantdeadline=true # -timeout defaults to 10m
9go test -run=FuzzDeadline -timeout=0 -wantdeadline=false
10! go test -run=FuzzDeadline -timeout=1s -wantdeadline=false
11go test -run=FuzzDeadline -timeout=1s -wantdeadline=true
12go test -fuzz=FuzzDeadline -timeout=0 -fuzztime=1s -wantdeadline=false
13go test -fuzz=FuzzDeadline -timeout=0 -fuzztime=100x -wantdeadline=false
14
15-- go.mod --
16module fuzz
17
18go 1.16
19-- fuzz_deadline_test.go --
20package fuzz_test
21
22import (
23 "flag"
24 "testing"
25)
26
27var wantDeadline = flag.Bool("wantdeadline", false, "whether the test should have a deadline")
28
29func FuzzDeadline(f *testing.F) {
30 f.Add("run once")
31 f.Fuzz(func (t *testing.T, _ string) {
32 if _, hasDeadline := t.Deadline(); hasDeadline != *wantDeadline {
33 t.Fatalf("function got %v; want %v", hasDeadline, *wantDeadline)
34 }
35 })
36}
View as plain text