Skip to content

Commit

Permalink
Lay groundwork for benchmark tests and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronH88 committed Jul 10, 2023
1 parent 8d5dcca commit 6999e70
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 11 deletions.
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
}

0 comments on commit 6999e70

Please sign in to comment.