Skip to content

Commit

Permalink
Added memory ballast e2e behavior test
Browse files Browse the repository at this point in the history
Added a new test that verifies that the ballast behaves only counts to
virtual memory and is not actually allocated.

Also added `tests/results/BASELINE.md` to act as the baseline test
results file. The TESTRESULTS.md file was modified on every run and it
would change in every PR from every contributor. It added additional
work when one didn't want to include it in a PR which was most of the
time. Only time it should be updated is when someone adds or updates a
new perf test.
  • Loading branch information
owais committed Jul 1, 2019
1 parent 21339fb commit f1b2ab1
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 3 deletions.
18 changes: 18 additions & 0 deletions testbed/testbed/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package testbed

// TestCaseOption defines a TestCase option
type TestCaseOption struct {
option func(t *TestCase)
}

// Apply takes a TestCase and runs the option function on it
func (o TestCaseOption) Apply(t *TestCase) {
o.option(t)
}

// WithSkipResults option disables writing out results file for a TestCase
func WithSkipResults() TestCaseOption {
return TestCaseOption{func(t *TestCase) {
t.skipResults = true
}}
}
29 changes: 26 additions & 3 deletions testbed/testbed/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type TestCase struct {
// Directory where test case results and logs will be written.
resultDir string

// does not write out results when set to true
skipResults bool

// Agent config file path.
agentConfigFile string

Expand Down Expand Up @@ -60,14 +63,18 @@ type TestCase struct {
const mibibyte = 1024 * 1024

// NewTestCase creates a new TestCase. It expected agent-config.yaml in the specified directory.
func NewTestCase(t *testing.T) *TestCase {
func NewTestCase(t *testing.T, opts ...TestCaseOption) *TestCase {
tc := TestCase{}

tc.t = t
tc.ErrorSignal = make(chan struct{})
tc.doneSignal = make(chan struct{})
tc.startTime = time.Now()

for _, opt := range opts {
opt.Apply(&tc)
}

var err error
tc.resultDir, err = filepath.Abs(path.Join("results", t.Name()))
if err != nil {
Expand Down Expand Up @@ -123,14 +130,16 @@ func (tc *TestCase) SetExpectedMaxRAM(ramMiB uint32) {

// StartAgent starts the agent and redirects its standard output and standard error
// to "agent.log" file located in the test directory.
func (tc *TestCase) StartAgent() {
func (tc *TestCase) StartAgent(args ...string) {
args = append(args, "--config")
args = append(args, tc.agentConfigFile)
logFileName := tc.composeTestResultFileName("agent.log")

err := tc.agentProc.start(startParams{
name: "Agent",
logFilePath: logFileName,
cmd: testBedConfig.Agent,
cmdArgs: []string{"--config", tc.agentConfigFile},
cmdArgs: args,
resourceSpec: &tc.resourceSpec,
})

Expand Down Expand Up @@ -180,6 +189,16 @@ func (tc *TestCase) StopBackend() {
tc.MockBackend.Stop()
}

// AgentMemoryInfo returns raw memory info struct about the agent
// as returned by github.com/shirou/gopsutil/process
func (tc *TestCase) AgentMemoryInfo() (uint32, uint32, error) {
stat, err := tc.agentProc.processMon.MemoryInfo()
if err != nil {
return 0, 0, err
}
return uint32(stat.RSS / mibibyte), uint32(stat.VMS / mibibyte), nil
}

// Stop stops the load generator, the agent and the backend.
func (tc *TestCase) Stop() {
// Stop all components
Expand All @@ -190,6 +209,10 @@ func (tc *TestCase) Stop() {
// Stop logging
close(tc.doneSignal)

if tc.skipResults {
return
}

// Report test results

rc := tc.agentProc.GetTotalConsumption()
Expand Down
1 change: 1 addition & 0 deletions testbed/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
results/*
!results/BASELINE.md
55 changes: 55 additions & 0 deletions testbed/tests/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2019, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package tests contains test cases. To run the tests go to tests directory and run:
// TESTBED_CONFIG=local.yaml go test -v

package tests

import (
"fmt"
"testing"
"strconv"

"github.com/stretchr/testify/assert"

"github.com/open-telemetry/opentelemetry-service/testbed/testbed"
)

func TestBallastMemory(t *testing.T) {
tests := []struct{
ballastSize uint32
maxRSS uint32
}{
{100, 50},
{500, 70},
{1000, 100},
}

for _, test := range tests {
tc := testbed.NewTestCase(t, testbed.WithSkipResults())
tc.SetExpectedMaxRAM(test.maxRSS)

tc.StartAgent("--mem-ballast-size-mib", strconv.Itoa(int(test.ballastSize)))

rss, vms, err := tc.AgentMemoryInfo()
if err != nil {
t.Fatal(err)
}

assert.True(t, rss <= test.maxRSS, fmt.Sprintf("RSS must be less than or equal to %d", test.maxRSS))
assert.True(t, vms > test.ballastSize, fmt.Sprintf("VMS must be greater than %d", test.ballastSize))
tc.Stop()
}
}
File renamed without changes.

0 comments on commit f1b2ab1

Please sign in to comment.