Skip to content

Commit

Permalink
[antithesis] Fix broken flag handling and improve image testing (#3299)
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava authored Aug 15, 2024
1 parent 9e77ecc commit aececb0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
14 changes: 4 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,10 @@ linters-settings:
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
- name: unhandled-error
disabled: false
arguments:
- "fmt\\.Fprint"
- "fmt\\.Fprintf"
- "fmt\\.Fprintln"
- "fmt\\.Print"
- "fmt\\.Printf"
- "fmt\\.Println"
- "math/rand\\.Read"
- "strings\\.Builder\\.WriteString"
# prefer the errcheck linter since it can be disabled directly with nolint directive
# but revive's disable directive (e.g. //revive:disable:unhandled-error) is not
# supported when run under golangci_lint
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
disabled: false
Expand Down
20 changes: 12 additions & 8 deletions scripts/lib_test_antithesis_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ docker cp "${CONTAINER_NAME}":/docker-compose.yml "${COMPOSE_FILE}"
# Copy the volume paths out of the container
docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/"

# Run the docker compose project for 30 seconds without error. Local
# network bootstrap is ~6s, but github workers can be much slower.
${COMPOSE_CMD} up -d
sleep 30
if ${COMPOSE_CMD} ps -q | xargs docker inspect -f '{{ .State.Status }}' | grep -v 'running'; then
echo "An error occurred."
# Wait for up to TIMEOUT for the workload to emit HEALTHY_MESSAGE to indicate that all nodes are
# reporting healthy. This indicates that the workload has been correctly configured. Subsequent
# validation will need to be tailored to a given workload implementation.

TIMEOUT=30s
HEALTHY_MESSAGE="all nodes reported healthy"

if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then
echo "Saw log containing '${HEALTHY_MESSAGE}'"
echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}"
else
echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}"
exit 1
fi

echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}"
12 changes: 5 additions & 7 deletions tests/antithesis/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"strconv"
"strings"

"github.com/compose-spec/compose-go/types"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -129,7 +128,7 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
baseNetworkAddress := "10.0.20"

services := make(types.Services, len(network.Nodes)+1)
uris := make([]string, len(network.Nodes))
uris := make(CSV, len(network.Nodes))
var (
bootstrapIP string
bootstrapIDs string
Expand Down Expand Up @@ -230,16 +229,16 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
}

workloadEnv := types.Mapping{
envVarName(URIsKey): strings.Join(uris, " "),
envVarName(EnvPrefix, URIsKey): uris.String(),
}
chainIDs := []string{}
chainIDs := CSV{}
for _, subnet := range network.Subnets {
for _, chain := range subnet.Chains {
chainIDs = append(chainIDs, chain.ChainID.String())
}
}
if len(chainIDs) > 0 {
workloadEnv[envVarName(ChainIDsKey)] = strings.Join(chainIDs, " ")
workloadEnv[envVarName(EnvPrefix, ChainIDsKey)] = chainIDs.String()
}

workloadName := "workload"
Expand Down Expand Up @@ -277,8 +276,7 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
func keyMapToEnvVarMap(keyMap types.Mapping) types.Mapping {
envVarMap := make(types.Mapping, len(keyMap))
for key, val := range keyMap {
// e.g. network-id -> AVAGO_NETWORK_ID
envVar := strings.ToUpper(config.EnvPrefix + "_" + config.DashesToUnderscores.Replace(key))
envVar := envVarName(config.EnvPrefix, key)
envVarMap[envVar] = val
}
return envVarMap
Expand Down
18 changes: 10 additions & 8 deletions tests/antithesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
Expand Down Expand Up @@ -54,15 +55,15 @@ func NewConfigWithSubnets(tc tests.TestContext, defaultNetwork *tmpnet.Network,
flag.Parse()

// Env vars take priority over flags
envURIs := os.Getenv(envVarName(URIsKey))
envURIs := os.Getenv(envVarName(EnvPrefix, URIsKey))
if len(envURIs) > 0 {
// CSV.Set doesn't actually return an error
_ = uris.Set(envURIs)
//nolint:errcheck // CSV.Set doesn't actually return an error
uris.Set(envURIs)
}
envChainIDs := os.Getenv(envVarName(ChainIDsKey))
envChainIDs := os.Getenv(envVarName(EnvPrefix, ChainIDsKey))
if len(envChainIDs) > 0 {
// CSV.Set doesn't actually return an error
_ = uris.Set(envChainIDs)
//nolint:errcheck // CSV.Set doesn't actually return an error
chainIDs.Set(envChainIDs)
}

// Use the network configuration provided
Expand Down Expand Up @@ -126,6 +127,7 @@ func (c *CSV) Set(value string) error {
return nil
}

func envVarName(key string) string {
return strings.ToUpper(EnvPrefix + "_" + key)
func envVarName(prefix string, key string) string {
// e.g. MY_PREFIX, network-id -> MY_PREFIX_NETWORK_ID
return strings.ToUpper(prefix + "_" + config.DashesToUnderscores.Replace(key))
}

0 comments on commit aececb0

Please sign in to comment.