瀏覽代碼

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,18 +399,6 @@ func TestHttpsInsecure(t *testing.T) {
399 399
 	}()
400 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 402
 	outputTempFile, err := ioutil.TempFile("", "profile_output")
415 403
 	if err != nil {
416 404
 		t.Fatalf("Failed to create tempfile: %v", err)
@@ -418,7 +406,7 @@ func TestHttpsInsecure(t *testing.T) {
418 406
 	defer os.Remove(outputTempFile.Name())
419 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 410
 	s := &source{
423 411
 		Sources:   []string{address},
424 412
 		Seconds:   10,
@@ -437,31 +425,14 @@ func TestHttpsInsecure(t *testing.T) {
437 425
 	if len(p.SampleType) == 0 {
438 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 428
 	if len(p.Function) == 0 {
451 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 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 436
 func checkProfileHasFunction(p *profile.Profile, fname string) error {
466 437
 	for _, f := range p.Function {
467 438
 		if strings.Contains(f.Name, fname) {