Skip to content

Commit

Permalink
fix(perftests): make Tracee stop gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
geyslan committed Feb 17, 2025
1 parent c2d4150 commit 0abfcab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 7 additions & 5 deletions tests/perftests/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func checkIfPprofExist() error {
//
// for the user running the tests.

// TestMetricsExist tests if the metrics endpoint returns all metrics.
func TestMetricsandPprofExist(t *testing.T) {
// TestMetricsAndPprofExist tests if the metrics endpoint returns all metrics.
func TestMetricsAndPprofExist(t *testing.T) {
// Make sure we don't leak any goroutines since we run Tracee many times in this test.
// If a test case fails, ignore the leak since it's probably caused by the aborted test.
defer goleak.VerifyNone(t)
Expand All @@ -107,11 +107,16 @@ func TestMetricsandPprofExist(t *testing.T) {
}

cmd := "--output none --events=syslog --metrics --pprof"
cmd = fmt.Sprintf("--http-listen-addr=:%d %s", testutils.TraceePort, cmd)
running := testutils.NewRunningTracee(context.Background(), cmd)

// start tracee
ready, runErr := running.Start(testutils.TraceeDefaultStartupTimeout)
require.NoError(t, runErr)
defer func() {
err := running.Stop()
require.Empty(t, err)
}()

r := <-ready // block until tracee is ready (or not)
switch r {
Expand All @@ -130,7 +135,4 @@ func TestMetricsandPprofExist(t *testing.T) {
// check if all metrics exist
require.NoError(t, metricsErr)
require.NoError(t, pprofErr)

cmdErrs := running.Stop() // stop tracee
require.Empty(t, cmdErrs)
}
8 changes: 6 additions & 2 deletions tests/testutils/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
const (
readinessPollTime = 200 * time.Millisecond
httpRequestTimeout = 1 * time.Second
TraceeDefaultStartupTimeout = 10 * time.Second
TraceeDefaultStartupTimeout = 15 * time.Second
)

var (
TraceeBinary = "../../dist/tracee"
TraceeHostname = "localhost"
TraceePort = 3366
TraceePort = 3369
)

type TraceeStatus int
Expand Down Expand Up @@ -53,6 +53,10 @@ func NewRunningTracee(givenCtx context.Context, cmdLine string) *RunningTracee {
cmdLine = fmt.Sprintf("--healthz %s", cmdLine)
}

if !strings.Contains(cmdLine, "--http-listen-addr") {
cmdLine = fmt.Sprintf("--http-listen-addr=:%d %s", TraceePort, cmdLine)
}

cmdLine = fmt.Sprintf("%s %s", TraceeBinary, cmdLine)

return &RunningTracee{
Expand Down

0 comments on commit 0abfcab

Please sign in to comment.