Skip to content

Commit

Permalink
tmpnet: Ensure nodes are properly detached from the parent process (#…
Browse files Browse the repository at this point in the history
…2859)

Signed-off-by: marun <[email protected]>
Signed-off-by: Stephen Buttolph <[email protected]>
Co-authored-by: Stephen Buttolph <[email protected]>
Co-authored-by: Darioush Jalali <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent 9833b45 commit c896704
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
15 changes: 12 additions & 3 deletions scripts/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
# Load the constants
source "$AVALANCHE_PATH"/scripts/constants.sh

# Ensure execution of fixture unit tests under tests/ but exclude ginkgo tests in tests/e2e and tests/upgrade
# shellcheck disable=SC2046
go test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" $(go list ./... | grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/upgrade)
EXCLUDED_TARGETS="| grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/upgrade"

GOOS=$(go env GOOS)
if [[ "$GOOS" == "windows" ]]; then
# tmpnet is not compatible with windows
EXCLUDED_TARGETS="${EXCLUDED_TARGETS} | grep -v tests/fixture"
fi

TEST_TARGETS="$(eval "go list ./... ${EXCLUDED_TARGETS}")"

# shellcheck disable=SC2086
go test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS}
5 changes: 3 additions & 2 deletions tests/fixture/tmpnet/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
)

Expand Down Expand Up @@ -46,8 +47,8 @@ func DefaultFlags() FlagsMap {
config.HealthCheckFreqKey: "2s",
config.AdminAPIEnabledKey: true,
config.IndexEnabledKey: true,
config.LogDisplayLevelKey: "INFO",
config.LogLevelKey: "DEBUG",
config.LogDisplayLevelKey: logging.Off.String(), // Display logging not needed since nodes run headless
config.LogLevelKey: logging.Debug.String(),
config.MinStakeDurationKey: DefaultMinStakeDuration.String(),
}
}
Expand Down
16 changes: 7 additions & 9 deletions tests/fixture/tmpnet/node_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ func (p *NodeProcess) Start(w io.Writer) error {
return fmt.Errorf("failed to remove stale process context file: %w", err)
}

// All arguments are provided in the flags file
cmd := exec.Command(p.node.RuntimeConfig.AvalancheGoPath, "--config-file", p.node.getFlagsPath()) // #nosec G204

// Ensure process is detached from the parent process so that an error in the parent will not affect the child
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}

if err := cmd.Start(); err != nil {
return err
}
Expand All @@ -129,15 +136,6 @@ func (p *NodeProcess) Start(w io.Writer) error {
nodeDescription = fmt.Sprintf("%s with path: %s", nodeDescription, dataDir)
}

go func() {
if err := cmd.Wait(); err != nil {
if err.Error() != "signal: killed" {
_, _ = fmt.Fprintf(w, "%s finished with error: %v\n", nodeDescription, err)
}
}
_, _ = fmt.Fprintf(w, "%s exited\n", nodeDescription)
}()

// A node writes a process context file on start. If the file is not
// found in a reasonable amount of time, the node is unlikely to have
// started successfully.
Expand Down

0 comments on commit c896704

Please sign in to comment.