Skip to content

Commit d7389ec

Browse files
committed
[antithesis] Fix broken flag handling and improve image testing
The recent addition of tmpnet support for antithesis workloads broke configuration in the actual antithesis environment due to deficiencies in the test of the image build. This change cleans up the flag configuration that caused the problem and updates the test of image build to directly check the output of the docker compose project for evidence that nodes have reported healthy rather than just waiting 30s for a non-zero exit.
1 parent 35b58d0 commit d7389ec

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

scripts/lib_test_antithesis_images.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ docker cp "${CONTAINER_NAME}":/docker-compose.yml "${COMPOSE_FILE}"
4646
# Copy the volume paths out of the container
4747
docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/"
4848

49-
# Run the docker compose project for 30 seconds without error. Local
50-
# network bootstrap is ~6s, but github workers can be much slower.
51-
${COMPOSE_CMD} up -d
52-
sleep 30
53-
if ${COMPOSE_CMD} ps -q | xargs docker inspect -f '{{ .State.Status }}' | grep -v 'running'; then
54-
echo "An error occurred."
49+
# Wait for up to TIMEOUT for the workload to emit HEALTHY_MESSAGE to indicate that all nodes are
50+
# reporting healthy. This indicates that the workload has been correctly configured. Subsequent
51+
# validation will need to be tailored to a given workload implementation.
52+
53+
TIMEOUT=30s
54+
HEALTHY_MESSAGE="all nodes reported healthy"
55+
56+
if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then
57+
echo "Saw log containing '${HEALTHY_MESSAGE}'"
58+
echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}"
59+
else
60+
echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}"
5561
exit 1
5662
fi
57-
58-
echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}"

tests/antithesis/compose.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"path/filepath"
1111
"strconv"
12-
"strings"
1312

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

131130
services := make(types.Services, len(network.Nodes)+1)
132-
uris := make([]string, len(network.Nodes))
131+
uris := make(CSV, len(network.Nodes))
133132
var (
134133
bootstrapIP string
135134
bootstrapIDs string
@@ -230,16 +229,16 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
230229
}
231230

232231
workloadEnv := types.Mapping{
233-
envVarName(URIsKey): strings.Join(uris, " "),
232+
envVarName(EnvPrefix, URIsKey): uris.String(),
234233
}
235-
chainIDs := []string{}
234+
chainIDs := CSV{}
236235
for _, subnet := range network.Subnets {
237236
for _, chain := range subnet.Chains {
238237
chainIDs = append(chainIDs, chain.ChainID.String())
239238
}
240239
}
241240
if len(chainIDs) > 0 {
242-
workloadEnv[envVarName(ChainIDsKey)] = strings.Join(chainIDs, " ")
241+
workloadEnv[envVarName(EnvPrefix, ChainIDsKey)] = chainIDs.String()
243242
}
244243

245244
workloadName := "workload"
@@ -277,8 +276,7 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
277276
func keyMapToEnvVarMap(keyMap types.Mapping) types.Mapping {
278277
envVarMap := make(types.Mapping, len(keyMap))
279278
for key, val := range keyMap {
280-
// e.g. network-id -> AVAGO_NETWORK_ID
281-
envVar := strings.ToUpper(config.EnvPrefix + "_" + config.DashesToUnderscores.Replace(key))
279+
envVar := envVarName(config.EnvPrefix, key)
282280
envVarMap[envVar] = val
283281
}
284282
return envVarMap

tests/antithesis/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/stretchr/testify/require"
1313

14+
"github.com/ava-labs/avalanchego/config"
1415
"github.com/ava-labs/avalanchego/tests"
1516
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
1617
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
@@ -54,15 +55,15 @@ func NewConfigWithSubnets(tc tests.TestContext, defaultNetwork *tmpnet.Network,
5455
flag.Parse()
5556

5657
// Env vars take priority over flags
57-
envURIs := os.Getenv(envVarName(URIsKey))
58+
envURIs := os.Getenv(envVarName(EnvPrefix, URIsKey))
5859
if len(envURIs) > 0 {
5960
// CSV.Set doesn't actually return an error
6061
_ = uris.Set(envURIs)
6162
}
62-
envChainIDs := os.Getenv(envVarName(ChainIDsKey))
63+
envChainIDs := os.Getenv(envVarName(EnvPrefix, ChainIDsKey))
6364
if len(envChainIDs) > 0 {
6465
// CSV.Set doesn't actually return an error
65-
_ = uris.Set(envChainIDs)
66+
_ = chainIDs.Set(envChainIDs)
6667
}
6768

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

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

0 commit comments

Comments
 (0)