@@ -90,7 +90,7 @@ func TestAnalyzeAnnotations(t *testing.T) {
90
90
// TODO: classify taskless spans
91
91
92
92
// Run prog0 and capture the execution trace.
93
- if err := traceProgram (prog0 , "TestAnalyzeAnnotations" ); err != nil {
93
+ if err := traceProgram (t , prog0 , "TestAnalyzeAnnotations" ); err != nil {
94
94
t .Fatalf ("failed to trace the program: %v" , err )
95
95
}
96
96
@@ -155,7 +155,7 @@ func prog1() {
155
155
156
156
func TestAnalyzeAnnotationTaskTree (t * testing.T ) {
157
157
// Run prog1 and capture the execution trace.
158
- if err := traceProgram (prog1 , "TestAnalyzeAnnotationTaskTree" ); err != nil {
158
+ if err := traceProgram (t , prog1 , "TestAnalyzeAnnotationTaskTree" ); err != nil {
159
159
t .Fatalf ("failed to trace the program: %v" , err )
160
160
}
161
161
@@ -239,7 +239,7 @@ func prog2() (gcTime time.Duration) {
239
239
240
240
func TestAnalyzeAnnotationGC (t * testing.T ) {
241
241
var gcTime time.Duration
242
- err := traceProgram (func () {
242
+ err := traceProgram (t , func () {
243
243
oldGC := debug .SetGCPercent (10000 ) // gc, and effectively disable GC
244
244
defer debug .SetGCPercent (oldGC )
245
245
@@ -272,9 +272,19 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
272
272
for _ , task := range res .tasks {
273
273
got := task .overlappingGCDuration (res .gcEvents )
274
274
switch task .name {
275
+ case "taskWithoutGC" :
276
+ if got != 0 {
277
+ t .Errorf ("%s reported %v as overlapping GC time; want 0: %v" , task .name , got , task )
278
+ }
275
279
case "taskWithGC" :
276
- if got <= 0 || got >= gcTime {
277
- t .Errorf ("%s reported %v as overlapping GC time; want (0, %v):\n %v" , task .name , got , gcTime , task )
280
+ upperBound := task .duration ()
281
+ // TODO(hyangah): a tighter upper bound is gcTime, but
282
+ // use of it will make the test flaky due to the issue
283
+ // described in golang.org/issue/16755. Tighten the upper
284
+ // bound when the issue with the timestamp computed
285
+ // based on clockticks is resolved.
286
+ if got <= 0 || got > upperBound {
287
+ t .Errorf ("%s reported %v as overlapping GC time; want (0, %v):\n %v" , task .name , got , upperBound , task )
278
288
buf := new (bytes.Buffer )
279
289
fmt .Fprintln (buf , "GC Events" )
280
290
for _ , ev := range res .gcEvents {
@@ -287,10 +297,6 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
287
297
288
298
t .Logf ("\n %s" , buf )
289
299
}
290
- case "taskWithoutGC" :
291
- if got != 0 {
292
- t .Errorf ("%s reported %v as overlapping GC time; want 0: %v" , task .name , got , task )
293
- }
294
300
}
295
301
}
296
302
}
@@ -300,7 +306,8 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
300
306
// point to the parsed trace.
301
307
//
302
308
// If savetraces flag is set, the captured trace will be saved in the named file.
303
- func traceProgram (f func (), name string ) error {
309
+ func traceProgram (t * testing.T , f func (), name string ) error {
310
+ t .Helper ()
304
311
buf := new (bytes.Buffer )
305
312
if err := trace .Start (buf ); err != nil {
306
313
return err
@@ -310,7 +317,9 @@ func traceProgram(f func(), name string) error {
310
317
311
318
saveTrace (buf , name )
312
319
res , err := traceparser .Parse (buf , name + ".faketrace" )
313
- if err != nil {
320
+ if err == traceparser .ErrTimeOrder {
321
+ t .Skipf ("skipping due to golang.org/issue/16755: %v" , err )
322
+ } else if err != nil {
314
323
return err
315
324
}
316
325
0 commit comments