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

github/workflows: run compose tests #637

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 18 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.out

integration_tests:
app_tests:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -45,3 +45,20 @@ jobs:
${{ runner.os }}-go-
- run: docker pull consensys/teku:latest
- run: go test -timeout=5m -v github.com/obolnetwork/charon/app -integration -slow

compose_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.18.0'
- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go test -v github.com/obolnetwork/charon/testutil/compose/compose -integration
34 changes: 31 additions & 3 deletions testutil/compose/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,40 @@ func newAutoCmd(tmplCallback func(data *compose.TmplData)) *cobra.Command {
cmd := &cobra.Command{
Use: "auto",
Short: "Convenience function that runs `compose define && compose lock && compose run`",
Args: cobra.NoArgs,
}

dir := addDirFlag(cmd.Flags())
alertTimeout := cmd.Flags().Duration("alert-timeout", 0, "Timeout to collect alerts before shutdown. Zero disables timeout.")
sudoPerms := cmd.Flags().Bool("sudo-perms", false, "Enables changing all compose artefacts file permissions using sudo.")

cmd.RunE = func(cmd *cobra.Command, _ []string) (err error) {
runFuncs := []func(context.Context) (compose.TmplData, error){
newRunnerFunc("define", *dir, true, compose.Define),
newRunnerFunc("lock", *dir, true, compose.Lock),
newRunnerFunc("define", *dir, false, compose.Define),
newRunnerFunc("lock", *dir, false, compose.Lock),
newRunnerFunc("run", *dir, false, compose.Run),
}

rootCtx := log.WithTopic(cmd.Context(), "auto")

var lastTmpl compose.TmplData
for _, runFunc := range runFuncs {
for i, runFunc := range runFuncs {
lastTmpl, err = runFunc(rootCtx)
if err != nil {
return err
}

if *sudoPerms {
if err := fixPerms(rootCtx, *dir); err != nil {
return err
}
}

if i < len(runFuncs)-1 {
if err := execUp(rootCtx, *dir); err != nil {
return err
}
}
}

if tmplCallback != nil {
Expand Down Expand Up @@ -195,6 +209,20 @@ func newAutoCmd(tmplCallback func(data *compose.TmplData)) *cobra.Command {
return cmd
}

func fixPerms(ctx context.Context, dir string) error {
cmd := exec.CommandContext(ctx, "sudo", "chmod", "-R", "a+wrX", ".")
cmd.Dir = dir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Run()
if err != nil {
return errors.Wrap(err, "exec sudo chmod")
}

return nil
}

func newNewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "new",
Expand Down
36 changes: 17 additions & 19 deletions testutil/compose/compose/smoke_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"flag"
"os"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -28,6 +27,7 @@ import (
)

//go:generate go test . -run=TestSmoke -integration -v

var integration = flag.Bool("integration", false, "Enable docker based integration test")

func TestSmoke(t *testing.T) {
Expand Down Expand Up @@ -68,12 +68,12 @@ func TestSmoke(t *testing.T) {
},
},
{
Name: "very large dkg",
Name: "very large",
ConfigFunc: func(conf *compose.Config) {
conf.NumNodes = 21
conf.Threshold = 14
conf.NumValidators = 1000
conf.KeyGen = compose.KeyGenDKG
conf.KeyGen = compose.KeyGenCreate
},
},
{
Expand All @@ -97,17 +97,18 @@ func TestSmoke(t *testing.T) {
data.VCs[3].Image = "consensys/teku:22.3"
},
},
{
Name: "1 of 4 down",
TmplFunc: func(data *compose.TmplData) {
node0 := data.Nodes[0]
for i := 0; i < len(node0.EnvVars); i++ {
if strings.HasPrefix(node0.EnvVars[i].Key, "p2p") {
data.Nodes[0].EnvVars[i].Key = "unset" // Zero p2p flags to it cannot communicate
}
}
},
},
// TODO(corver): Enable after https://github.com/ObolNetwork/charon/issues/635
//{
// Name: "1 of 4 down",
// TmplFunc: func(data *compose.TmplData) {
// node0 := data.Nodes[0]
// for i := 0; i < len(node0.EnvVars); i++ {
// if strings.HasPrefix(node0.EnvVars[i].Key, "p2p") {
// data.Nodes[0].EnvVars[i].Key = "unset" // Zero p2p flags to it cannot communicate
// }
// }
// },
// },
}

for _, test := range tests {
Expand All @@ -129,14 +130,11 @@ func TestSmoke(t *testing.T) {
})
require.NoError(t, cmd.Flags().Set("compose-dir", dir))
require.NoError(t, cmd.Flags().Set("alert-timeout", "30s"))
require.NoError(t, cmd.Flags().Set("sudo-perms", "true"))
os.Args = []string{"cobra.test"}

err = cmd.ExecuteContext(context.Background())
require.NoError(t, err)
})
}
}

// TestFlagFalse ensures the integration flag default value is false.
func TestFlagFalse(t *testing.T) {
require.False(t, *integration)
}
9 changes: 3 additions & 6 deletions testutil/compose/docker-compose.template
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ services:
{{if .Monitoring}}
prometheus:
image: prom/prometheus:latest
{{- if .MonitoringPorts}}
ports:
{{if .MonitoringPorts}}ports:
- "9090:9090"
{{end -}}
networks: [compose]
Expand All @@ -70,8 +69,7 @@ services:

grafana:
image: grafana/grafana:latest
{{- if .MonitoringPorts}}
ports:
{{if .MonitoringPorts}}ports:
- "3000:3000"
{{end -}}
networks: [compose]
Expand All @@ -86,8 +84,7 @@ services:
jaeger:
image: jaegertracing/all-in-one:latest
networks: [compose]
{{- if .MonitoringPorts}}
ports:
{{if .MonitoringPorts}}ports:
- "16686:16686"
{{end -}}
{{end}}
Expand Down