mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-19 03:25:16 +00:00
65aaa607ab
Change made by: - running "gvt fetch" on each of the packages mentioned in Godeps/Godeps.json - `rm -rf Godeps` - tweaking the build scripts to not mention Godeps - tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly (to avoid testing vendor) - tweaking the build scripts to not juggle GOPATH for Godeps and instead set GO15VENDOREXPERIMENT. This also results in some updated packages at the same time I bet. Building with Go 1.3 and 1.4 still *works* but won't use our vendored dependencies - the user needs to have the actual packages in their GOPATH then, which they'll get with a normal "go get". Building with Go 1.6+ will get our vendored dependencies by default even when not using our build script, which is nice. By doing this we gain some freedom in that we can pick and choose manually what to include in vendor, as it's not based on just dependency analysis of our own code. This is also a risk as we might pick up dependencies we are unaware of, as the build may work locally with those packages present in GOPATH. On the other hand the build server will detect this as it has no packages in it's GOPATH beyond what is included in the repo. Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package metrics
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func BenchmarkRuntimeMemStats(b *testing.B) {
|
|
r := NewRegistry()
|
|
RegisterRuntimeMemStats(r)
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
}
|
|
}
|
|
|
|
func TestRuntimeMemStats(t *testing.T) {
|
|
r := NewRegistry()
|
|
RegisterRuntimeMemStats(r)
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
zero := runtimeMetrics.MemStats.PauseNs.Count() // Get a "zero" since GC may have run before these tests.
|
|
runtime.GC()
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
if count := runtimeMetrics.MemStats.PauseNs.Count(); 1 != count-zero {
|
|
t.Fatal(count - zero)
|
|
}
|
|
runtime.GC()
|
|
runtime.GC()
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
if count := runtimeMetrics.MemStats.PauseNs.Count(); 3 != count-zero {
|
|
t.Fatal(count - zero)
|
|
}
|
|
for i := 0; i < 256; i++ {
|
|
runtime.GC()
|
|
}
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
if count := runtimeMetrics.MemStats.PauseNs.Count(); 259 != count-zero {
|
|
t.Fatal(count - zero)
|
|
}
|
|
for i := 0; i < 257; i++ {
|
|
runtime.GC()
|
|
}
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
if count := runtimeMetrics.MemStats.PauseNs.Count(); 515 != count-zero { // We lost one because there were too many GCs between captures.
|
|
t.Fatal(count - zero)
|
|
}
|
|
}
|
|
|
|
func TestRuntimeMemStatsNumThread(t *testing.T) {
|
|
r := NewRegistry()
|
|
RegisterRuntimeMemStats(r)
|
|
CaptureRuntimeMemStatsOnce(r)
|
|
|
|
if value := runtimeMetrics.NumThread.Value(); value < 1 {
|
|
t.Fatalf("got NumThread: %d, wanted at least 1", value)
|
|
}
|
|
}
|
|
|
|
func TestRuntimeMemStatsBlocking(t *testing.T) {
|
|
if g := runtime.GOMAXPROCS(0); g < 2 {
|
|
t.Skipf("skipping TestRuntimeMemStatsBlocking with GOMAXPROCS=%d\n", g)
|
|
}
|
|
ch := make(chan int)
|
|
go testRuntimeMemStatsBlocking(ch)
|
|
var memStats runtime.MemStats
|
|
t0 := time.Now()
|
|
runtime.ReadMemStats(&memStats)
|
|
t1 := time.Now()
|
|
t.Log("i++ during runtime.ReadMemStats:", <-ch)
|
|
go testRuntimeMemStatsBlocking(ch)
|
|
d := t1.Sub(t0)
|
|
t.Log(d)
|
|
time.Sleep(d)
|
|
t.Log("i++ during time.Sleep:", <-ch)
|
|
}
|
|
|
|
func testRuntimeMemStatsBlocking(ch chan int) {
|
|
i := 0
|
|
for {
|
|
select {
|
|
case ch <- i:
|
|
return
|
|
default:
|
|
i++
|
|
}
|
|
}
|
|
}
|