Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lay groundwork for benchmark tests and reporting #804

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ testloop: receptor
make test; do \
i=$$((i+1)); done

benchmark:
PATH="${PWD}:${PATH}" \
go test -bench=. -run=^# ./...


kubectl:
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod a+x kubectl
Expand Down
39 changes: 37 additions & 2 deletions tests/functional/mesh/work_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@ func TestWorkSubmitWithTLSClient(t *testing.T) {
}
}

func BenchmarkWorkSubmitWithTLSClient(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, plugin := range workPlugins {
plugin := plugin

b.Run(string(plugin), func(b *testing.B) {
controllers, m, expectedResults := benchWorkSetup(plugin, b)

defer m.WaitForShutdown()
defer m.Destroy()

command := `{"command":"work","subcommand":"submit","worktype":"echosleepshort","tlsclient":"client","node":"node2","params":"", "ttl":"10h"}`
unitID, err := controllers["node1"].WorkSubmitJSON(command)
if err != nil {
b.Fatal(err, m.DataDir)
}
ctx, _ := context.WithTimeout(context.Background(), 60*time.Second)
err = controllers["node1"].AssertWorkSucceeded(ctx, unitID)
if err != nil {
b.Fatal(err, m.DataDir)
}

err = controllers["node1"].AssertWorkResults(unitID, expectedResults)
if err != nil {
b.Fatal(err, m.GetDataDir())
}
})
}
}
}

// Tests that submitting work with wrong cert CN immediately fails the job
// also tests that releasing a job that has not been started on remote
// will not attempt to connect to remote.
Expand Down Expand Up @@ -490,7 +521,9 @@ func TestRuntimeParams(t *testing.T) {
}

func TestKubeRuntimeParams(t *testing.T) {
checkSkipKube(t)
if checkSkipKube() {
t.Skip("Kubernetes tests are set to skip, unset SKIP_KUBE to run them")
}

m := NewLibMesh()
node1 := m.NewLibNode("node1")
Expand Down Expand Up @@ -610,7 +643,9 @@ func TestRuntimeParamsNotAllowed(t *testing.T) {
}

func TestKubeContainerFailure(t *testing.T) {
checkSkipKube(t)
if checkSkipKube() {
t.Skip("Kubernetes tests are set to skip, unset SKIP_KUBE to run them")
}

m := NewLibMesh()
node1 := m.NewLibNode("node1")
Expand Down
44 changes: 35 additions & 9 deletions tests/functional/mesh/work_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ import (
"github.com/ansible/receptor/tests/utils"
)

func workSetup(workPluginName workPlugin, t *testing.T) (map[string]*ReceptorControl, *LibMesh, []byte) {
checkSkipKube(t)

func setupCommon(workPluginName workPlugin, name string) (map[string]*ReceptorControl, *LibMesh, error) {
m := workTestMesh(workPluginName)

err := m.Start(t.Name())
err := m.Start(name)
if err != nil {
t.Fatal(err)
return nil, nil, err
}

ctx, _ := context.WithTimeout(context.Background(), 120*time.Second)
err = m.WaitForReady(ctx)
if err != nil {
t.Fatal(err, m.DataDir)
return nil, nil, err
}

nodes := m.GetNodes()
Expand All @@ -33,11 +31,37 @@ func workSetup(workPluginName workPlugin, t *testing.T) (map[string]*ReceptorCon
controller := NewReceptorControl()
err = controller.Connect(nodes[k].GetControlSocket())
if err != nil {
t.Fatal(err, m.DataDir)
return nil, nil, err
}
controllers[k] = controller
}

return controllers, m, nil
}

func workSetup(workPluginName workPlugin, t *testing.T) (map[string]*ReceptorControl, *LibMesh, []byte) {
if checkSkipKube() {
t.Skip("Kubernetes tests are set to skip, unset SKIP_KUBE to run them")
}

controllers, m, err := setupCommon(workPluginName, t.Name())
if err != nil {
t.Fatal(err, m.DataDir)
}

return controllers, m, []byte("1\n2\n3\n4\n5\n")
}

func benchWorkSetup(workPluginName workPlugin, b *testing.B) (map[string]*ReceptorControl, *LibMesh, []byte) {
if checkSkipKube() {
b.Skip("Kubernetes tests are set to skip, unset SKIP_KUBE to run them")
}

controllers, m, err := setupCommon(workPluginName, b.Name())
if err != nil {
b.Fatal(err, m.DataDir)
}

return controllers, m, []byte("1\n2\n3\n4\n5\n")
}

Expand Down Expand Up @@ -73,8 +97,10 @@ func assertStdoutFizeSize(ctx context.Context, dataDir, nodeID, unitID string, w
return nil
}

func checkSkipKube(t *testing.T) {
func checkSkipKube() bool {
if skip := os.Getenv("SKIP_KUBE"); skip == "1" {
t.Skip("Kubernetes tests are set to skip, unset SKIP_KUBE to run them")
return true
}

return false
}