Skip to content

Commit

Permalink
Fixed ballast test cases by using cross-platform lib (#61)
Browse files Browse the repository at this point in the history
* Fixed ballast test cases by using  cross-platform lib

The ballast test case unreliable across platforms so had to remove it.
It'll be replaced with an external test case as leveraging the
performance testbed.

The latest version was working on Linux and macOS laptops but had a hard
time on Travis CI. It seems the only reliable way to test ballast is to
spin up an external collector process and monitor it's memory usage.
This will be implemented as part one of the perf testbed cases.
  • Loading branch information
owais authored and Paulo Janotti committed Jun 27, 2019
1 parent 2ad0e1d commit d05ec08
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 71 deletions.
71 changes: 0 additions & 71 deletions cmd/occollector/app/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ package collector
import (
"net"
"net/http"
"os"
"runtime"
"testing"

stats "github.com/guillermo/go.procstat"

"github.com/open-telemetry/opentelemetry-service/internal/testutils"

"github.com/open-telemetry/opentelemetry-service/internal/zpagesserver"
)

Expand Down Expand Up @@ -103,72 +98,6 @@ func TestApplication_StartUnified(t *testing.T) {
<-appDone
}

func testMemBallast(t *testing.T, app *Application, ballastSizeMiB int) {
maxRssBytes := mibToBytes(50)
minVirtualBytes := mibToBytes(ballastSizeMiB)

portArg := []string{
healthCheckHTTPPort, // Keep it as first since its address is used later.
zpagesserver.ZPagesHTTPPort,
"metrics-port",
"receivers.opencensus.port",
}

addresses := getMultipleAvailableLocalAddresses(t, uint(len(portArg)))
for i, addr := range addresses {
_, port, err := net.SplitHostPort(addr)
if err != nil {
t.Fatalf("failed to split host and port from %q: %v", addr, err)
}
app.v.Set(portArg[i], port)
}

// Without exporters the collector will start and just shutdown, no error is expected.
app.v.Set("logging-exporter", true)
app.v.Set("mem-ballast-size-mib", ballastSizeMiB)

appDone := make(chan struct{})
go func() {
defer close(appDone)
if err := app.Start(); err != nil {
t.Fatalf("app.Start() got %v, want nil", err)
}
}()

<-app.readyChan
if !isAppAvailable(t, "http://"+addresses[0]) {
t.Fatalf("app didn't reach ready state")
}
stats := stats.Stat{Pid: os.Getpid()}
err := stats.Update()
if err != nil {
panic(err)
}

if stats.Vsize < minVirtualBytes {
t.Errorf("unexpected virtual memory size. expected: >=%d, got: %d", minVirtualBytes, stats.Vsize)
}

if stats.Rss > maxRssBytes {
t.Errorf("unexpected RSS size. expected: <%d, got: %d", maxRssBytes, stats.Rss)
}

close(app.stopTestChan)
<-appDone
}

// TestApplication_MemBallast starts a new instance of collector with different
// mem ballast sizes and ensures that ballast consumes virtual memory but does
// not count towards RSS mem
func TestApplication_MemBallast(t *testing.T) {
cases := []int{0, 500, 1000}
for i := 0; i < len(cases); i++ {
runtime.GC()
app := newApp()
testMemBallast(t, app, cases[i])
}
}

// isAppAvailable checks if the healthcheck server at the given endpoint is
// returning `available`.
func isAppAvailable(t *testing.T, healthCheckEndPoint string) bool {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1
github.com/prometheus/prometheus v0.0.0-20190131111325-62e591f928dd
github.com/rs/cors v1.6.0
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/soheilhy/cmux v0.1.4
github.com/spf13/cast v1.2.0
github.com/spf13/cobra v0.0.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ github.com/sasha-s/go-deadlock v0.0.0-20161201235124-341000892f3d/go.mod h1:StQn
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20180711163814-62bca832be04/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
Expand Down

0 comments on commit d05ec08

Please sign in to comment.