@@ -16,19 +16,23 @@ import (
1616// in different formats with the expected stack frames.
1717func TestStart (t * testing.T ) {
1818 tests := []struct {
19+ // Sampling duration
20+ Duration time.Duration
1921 // Format is the export format being tested
2022 Format Format
2123 // ContainsStack returns true if the given profile contains a frame with the given name
2224 ContainsStack func (t * testing.T , prof * bytes.Buffer , frame string ) bool
2325 }{
2426 {
25- Format : FormatFolded ,
27+ Duration : 100 * time .Millisecond ,
28+ Format : FormatFolded ,
2629 ContainsStack : func (t * testing.T , prof * bytes.Buffer , frame string ) bool {
2730 return strings .Contains (prof .String (), frame )
2831 },
2932 },
3033 {
31- Format : FormatPprof ,
34+ Duration : 100 * time .Millisecond ,
35+ Format : FormatPprof ,
3236 ContainsStack : func (t * testing.T , prof * bytes.Buffer , frame string ) bool {
3337 pprof , err := profile .ParseData (prof .Bytes ())
3438 require .NoError (t , err )
@@ -45,13 +49,24 @@ func TestStart(t *testing.T) {
4549 return false
4650 },
4751 },
52+ // check divide by zero
53+ {
54+ Duration : 0 ,
55+ Format : FormatPprof ,
56+ ContainsStack : func (t * testing.T , prof * bytes.Buffer , frame string ) bool {
57+ pprof , err := profile .ParseData (prof .Bytes ())
58+ require .NoError (t , err )
59+ require .NoError (t , pprof .CheckValid ())
60+ return "fgprof.TestStart" == frame
61+ },
62+ },
4863 }
4964
5065 for _ , test := range tests {
5166 t .Run (string (test .Format ), func (t * testing.T ) {
5267 prof := & bytes.Buffer {}
5368 stop := Start (prof , test .Format )
54- time .Sleep (100 * time . Millisecond )
69+ time .Sleep (test . Duration )
5570 if err := stop (); err != nil {
5671 t .Fatal (err )
5772 }
0 commit comments