Skip to content

Commit d05ec08

Browse files
owaisPaulo Janotti
authored andcommitted
Fixed ballast test cases by using cross-platform lib (#61)
* 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.
1 parent 2ad0e1d commit d05ec08

File tree

3 files changed

+3
-71
lines changed

3 files changed

+3
-71
lines changed

cmd/occollector/app/collector/collector_test.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ package collector
1818
import (
1919
"net"
2020
"net/http"
21-
"os"
22-
"runtime"
2321
"testing"
2422

25-
stats "github.com/guillermo/go.procstat"
26-
2723
"github.com/open-telemetry/opentelemetry-service/internal/testutils"
28-
2924
"github.com/open-telemetry/opentelemetry-service/internal/zpagesserver"
3025
)
3126

@@ -103,72 +98,6 @@ func TestApplication_StartUnified(t *testing.T) {
10398
<-appDone
10499
}
105100

106-
func testMemBallast(t *testing.T, app *Application, ballastSizeMiB int) {
107-
maxRssBytes := mibToBytes(50)
108-
minVirtualBytes := mibToBytes(ballastSizeMiB)
109-
110-
portArg := []string{
111-
healthCheckHTTPPort, // Keep it as first since its address is used later.
112-
zpagesserver.ZPagesHTTPPort,
113-
"metrics-port",
114-
"receivers.opencensus.port",
115-
}
116-
117-
addresses := getMultipleAvailableLocalAddresses(t, uint(len(portArg)))
118-
for i, addr := range addresses {
119-
_, port, err := net.SplitHostPort(addr)
120-
if err != nil {
121-
t.Fatalf("failed to split host and port from %q: %v", addr, err)
122-
}
123-
app.v.Set(portArg[i], port)
124-
}
125-
126-
// Without exporters the collector will start and just shutdown, no error is expected.
127-
app.v.Set("logging-exporter", true)
128-
app.v.Set("mem-ballast-size-mib", ballastSizeMiB)
129-
130-
appDone := make(chan struct{})
131-
go func() {
132-
defer close(appDone)
133-
if err := app.Start(); err != nil {
134-
t.Fatalf("app.Start() got %v, want nil", err)
135-
}
136-
}()
137-
138-
<-app.readyChan
139-
if !isAppAvailable(t, "http://"+addresses[0]) {
140-
t.Fatalf("app didn't reach ready state")
141-
}
142-
stats := stats.Stat{Pid: os.Getpid()}
143-
err := stats.Update()
144-
if err != nil {
145-
panic(err)
146-
}
147-
148-
if stats.Vsize < minVirtualBytes {
149-
t.Errorf("unexpected virtual memory size. expected: >=%d, got: %d", minVirtualBytes, stats.Vsize)
150-
}
151-
152-
if stats.Rss > maxRssBytes {
153-
t.Errorf("unexpected RSS size. expected: <%d, got: %d", maxRssBytes, stats.Rss)
154-
}
155-
156-
close(app.stopTestChan)
157-
<-appDone
158-
}
159-
160-
// TestApplication_MemBallast starts a new instance of collector with different
161-
// mem ballast sizes and ensures that ballast consumes virtual memory but does
162-
// not count towards RSS mem
163-
func TestApplication_MemBallast(t *testing.T) {
164-
cases := []int{0, 500, 1000}
165-
for i := 0; i < len(cases); i++ {
166-
runtime.GC()
167-
app := newApp()
168-
testMemBallast(t, app, cases[i])
169-
}
170-
}
171-
172101
// isAppAvailable checks if the healthcheck server at the given endpoint is
173102
// returning `available`.
174103
func isAppAvailable(t *testing.T, healthCheckEndPoint string) bool {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1
3232
github.com/prometheus/prometheus v0.0.0-20190131111325-62e591f928dd
3333
github.com/rs/cors v1.6.0
34+
github.com/shirou/gopsutil v2.18.12+incompatible
3435
github.com/soheilhy/cmux v0.1.4
3536
github.com/spf13/cast v1.2.0
3637
github.com/spf13/cobra v0.0.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ github.com/sasha-s/go-deadlock v0.0.0-20161201235124-341000892f3d/go.mod h1:StQn
302302
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
303303
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
304304
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
305+
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
306+
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
305307
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
306308
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
307309
github.com/shurcooL/vfsgen v0.0.0-20180711163814-62bca832be04/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=

0 commit comments

Comments
 (0)