Explorar el Código

Make TestHttpsInsecure test reliably passing on Darwin. (#171)

* Make TestHttpsInsecure test reliably passing on Darwin.

TestHttpsInsecure test runs a profiling session and checks that the
results contain expected function name. On OSX prior to 10.11 El Capitan
the SIGPROF signal is delivered to the process rather than to the thread
which skews the results enough for the test to fail.

Relax the check when running on OSX and other operating systems known to
have issues with the profiling signal (the list is taken from
src/runtime/pprof/pprof_test.go in Go source).

Also add the multiple variants of OSX to the continuous testing.

Fixes #146 and #156.

* Document the motivation for the empty loop.
Alexey Alexandrov hace 7 años
padre
commit
21215464ba
Se han modificado 2 ficheros con 46 adiciones y 11 borrados
  1. 26
    7
      .travis.yml
  2. 20
    4
      internal/driver/fetch_test.go

+ 26
- 7
.travis.yml Ver fichero

@@ -1,14 +1,33 @@
1 1
 language: go
2
-go:
3
-  - 1.7.x
4
-  - 1.8.x
5
-  - master
6 2
 
7 3
 go_import_path: github.com/google/pprof
8 4
 
9
-os:
10
-  - linux
11
-  - osx
5
+matrix:
6
+  include:
7
+    - os: linux
8
+      go: 1.7.x
9
+    - os: linux
10
+      go: 1.8.x
11
+    - os: linux
12
+      go: master
13
+    - os: osx
14
+      osx_image: xcode6.4
15
+      go: 1.8.x
16
+    - os: osx
17
+      osx_image: xcode6.4
18
+      go: master
19
+    - os: osx
20
+      osx_image: xcode7.3
21
+      go: 1.8.x
22
+    - os: osx
23
+      osx_image: xcode7.3
24
+      go: master
25
+    - os: osx
26
+      osx_image: xcode8.3
27
+      go: 1.8.x
28
+    - os: osx
29
+      osx_image: xcode8.3
30
+      go: master
12 31
 
13 32
 addons:
14 33
   apt:

+ 20
- 4
internal/driver/fetch_test.go Ver fichero

@@ -381,7 +381,12 @@ func TestHttpsInsecure(t *testing.T) {
381 381
 	go func() {
382 382
 		deadline := time.Now().Add(5 * time.Second)
383 383
 		for time.Now().Before(deadline) {
384
-			// Simulate a hotspot function.
384
+			// Simulate a hotspot function. Spin in the inner loop for 100M iterations
385
+			// to ensure we get most of the samples landed here rather than in the
386
+			// library calls. We assume Go compiler won't elide the empty loop.
387
+			for i := 0; i < 1e8; i++ {
388
+			}
389
+			runtime.Gosched()
385 390
 		}
386 391
 	}()
387 392
 
@@ -409,13 +414,24 @@ func TestHttpsInsecure(t *testing.T) {
409 414
 		t.Fatal(err)
410 415
 	}
411 416
 	if len(p.SampleType) == 0 {
412
-		t.Fatalf("grabProfile(%s) got empty profile: len(p.SampleType)==0", address)
417
+		t.Fatalf("fetchProfiles(%s) got empty profile: len(p.SampleType)==0", address)
418
+	}
419
+	if len(p.Function) == 0 {
420
+		t.Fatalf("fetchProfiles(%s) got non-symbolized profile: len(p.Function)==0", address)
413 421
 	}
414
-	if err := checkProfileHasFunction(p, "TestHttpsInsecure"); err != nil {
415
-		t.Fatalf("grabProfile(%s) %v", address, err)
422
+	if err := checkProfileHasFunction(p, "TestHttpsInsecure"); !badSigprofOS[runtime.GOOS] && err != nil {
423
+		t.Fatalf("fetchProfiles(%s) %v", address, err)
416 424
 	}
417 425
 }
418 426
 
427
+// Some operating systems don't trigger the profiling signal right.
428
+// See https://github.com/golang/go/issues/13841.
429
+var badSigprofOS = map[string]bool{
430
+	"darwin": true,
431
+	"netbsd": true,
432
+	"plan9":  true,
433
+}
434
+
419 435
 func checkProfileHasFunction(p *profile.Profile, fname string) error {
420 436
 	for _, f := range p.Function {
421 437
 		if strings.Contains(f.Name, fname) {