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