Skip to content

Commit

Permalink
[tmpnet] Ensure tmpnet compatibility with windows
Browse files Browse the repository at this point in the history
This avoids breaking unit test discovery for any package that imports
tmpnet.
  • Loading branch information
marun committed May 13, 2024
1 parent 4ac6138 commit 308c57b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
6 changes: 0 additions & 6 deletions scripts/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ source "$AVALANCHE_PATH"/scripts/constants.sh

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 and antithesis tests (which depend on tmpnet) are not compatible with windows
EXCLUDED_TARGETS="${EXCLUDED_TARGETS} | grep -v tests/fixture | grep -v tests/antithesis"
fi

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

# shellcheck disable=SC2086
Expand Down
17 changes: 17 additions & 0 deletions tests/fixture/tmpnet/detached_process_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build linux || darwin

package tmpnet

import (
"os/exec"
"syscall"
)

func configureDetachedProcess(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
}
17 changes: 17 additions & 0 deletions tests/fixture/tmpnet/detached_process_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build windows

package tmpnet

import (
"os/exec"
"syscall"
)

func configureDetachedProcess(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
}
5 changes: 1 addition & 4 deletions tests/fixture/tmpnet/node_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,8 @@ func (p *NodeProcess) Start(w io.Writer) error {

// 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,
}
configureDetachedProcess(cmd)

if err := cmd.Start(); err != nil {
return err
Expand Down

0 comments on commit 308c57b

Please sign in to comment.