Переглянути джерело

Switch to use goroutine profile in TestHttpsInsecure. (#350)

Trying to test against /debug/pprof/profile has been giving some flakes
and trouble so far (#146, #253, #328, golang/go#24611, golang/go#22594). While
some of the discussions the failures triggered appear to be useful (such
as whether CPU profiles are expected to be working on Windows XP or
not), that kind of testing is not really in the scope for this
particular test. This change switches the test to use goroutine profile
instead which is hopefully much less dependent on the environment. The
change also makes the test much faster to run.
Alexey Alexandrov 7 роки тому
джерело
коміт
36d5638be8
1 змінених файлів з 2 додано та 31 видалено
  1. 2
    31
      internal/driver/fetch_test.go

+ 2
- 31
internal/driver/fetch_test.go Переглянути файл

399
 	}()
399
 	}()
400
 	defer l.Close()
400
 	defer l.Close()
401
 
401
 
402
-	go func() {
403
-		deadline := time.Now().Add(5 * time.Second)
404
-		for time.Now().Before(deadline) {
405
-			// Simulate a hotspot function. Spin in the inner loop for 100M iterations
406
-			// to ensure we get most of the samples landed here rather than in the
407
-			// library calls. We assume Go compiler won't elide the empty loop.
408
-			for i := 0; i < 1e8; i++ {
409
-			}
410
-			runtime.Gosched()
411
-		}
412
-	}()
413
-
414
 	outputTempFile, err := ioutil.TempFile("", "profile_output")
402
 	outputTempFile, err := ioutil.TempFile("", "profile_output")
415
 	if err != nil {
403
 	if err != nil {
416
 		t.Fatalf("Failed to create tempfile: %v", err)
404
 		t.Fatalf("Failed to create tempfile: %v", err)
418
 	defer os.Remove(outputTempFile.Name())
406
 	defer os.Remove(outputTempFile.Name())
419
 	defer outputTempFile.Close()
407
 	defer outputTempFile.Close()
420
 
408
 
421
-	address := "https+insecure://" + l.Addr().String() + "/debug/pprof/profile"
409
+	address := "https+insecure://" + l.Addr().String() + "/debug/pprof/goroutine"
422
 	s := &source{
410
 	s := &source{
423
 		Sources:   []string{address},
411
 		Sources:   []string{address},
424
 		Seconds:   10,
412
 		Seconds:   10,
437
 	if len(p.SampleType) == 0 {
425
 	if len(p.SampleType) == 0 {
438
 		t.Fatalf("fetchProfiles(%s) got empty profile: len(p.SampleType)==0", address)
426
 		t.Fatalf("fetchProfiles(%s) got empty profile: len(p.SampleType)==0", address)
439
 	}
427
 	}
440
-	switch runtime.GOOS {
441
-	case "plan9":
442
-		// CPU profiling is not supported on Plan9; see golang.org/issues/22564.
443
-		return
444
-	case "darwin":
445
-		if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
446
-			// CPU profiling on iOS os not symbolized; see golang.org/issues/22612.
447
-			return
448
-		}
449
-	}
450
 	if len(p.Function) == 0 {
428
 	if len(p.Function) == 0 {
451
 		t.Fatalf("fetchProfiles(%s) got non-symbolized profile: len(p.Function)==0", address)
429
 		t.Fatalf("fetchProfiles(%s) got non-symbolized profile: len(p.Function)==0", address)
452
 	}
430
 	}
453
-	if err := checkProfileHasFunction(p, "TestHttpsInsecure"); !badSigprofOS[runtime.GOOS] && err != nil {
431
+	if err := checkProfileHasFunction(p, "TestHttpsInsecure"); err != nil {
454
 		t.Fatalf("fetchProfiles(%s) %v", address, err)
432
 		t.Fatalf("fetchProfiles(%s) %v", address, err)
455
 	}
433
 	}
456
 }
434
 }
457
 
435
 
458
-// Some operating systems don't trigger the profiling signal right.
459
-// See https://github.com/golang/go/issues/13841.
460
-var badSigprofOS = map[string]bool{
461
-	"darwin": true,
462
-	"netbsd": true,
463
-}
464
-
465
 func checkProfileHasFunction(p *profile.Profile, fname string) error {
436
 func checkProfileHasFunction(p *profile.Profile, fname string) error {
466
 	for _, f := range p.Function {
437
 	for _, f := range p.Function {
467
 		if strings.Contains(f.Name, fname) {
438
 		if strings.Contains(f.Name, fname) {