From 308c57bcfe8c2ea786bb8658fd53d925fb3a6b44 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Mon, 6 May 2024 19:51:33 -0700 Subject: [PATCH 1/3] [tmpnet] Ensure tmpnet compatibility with windows This avoids breaking unit test discovery for any package that imports tmpnet. --- scripts/build_test.sh | 6 ------ tests/fixture/tmpnet/detached_process_others.go | 17 +++++++++++++++++ .../fixture/tmpnet/detached_process_windows.go | 17 +++++++++++++++++ tests/fixture/tmpnet/node_process.go | 5 +---- 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 tests/fixture/tmpnet/detached_process_others.go create mode 100644 tests/fixture/tmpnet/detached_process_windows.go diff --git a/scripts/build_test.sh b/scripts/build_test.sh index 747cb8882449..cfff1a2fc9fd 100755 --- a/scripts/build_test.sh +++ b/scripts/build_test.sh @@ -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 diff --git a/tests/fixture/tmpnet/detached_process_others.go b/tests/fixture/tmpnet/detached_process_others.go new file mode 100644 index 000000000000..0e4b20ddd8e3 --- /dev/null +++ b/tests/fixture/tmpnet/detached_process_others.go @@ -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, + } +} diff --git a/tests/fixture/tmpnet/detached_process_windows.go b/tests/fixture/tmpnet/detached_process_windows.go new file mode 100644 index 000000000000..34ee11fcc003 --- /dev/null +++ b/tests/fixture/tmpnet/detached_process_windows.go @@ -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, + } +} diff --git a/tests/fixture/tmpnet/node_process.go b/tests/fixture/tmpnet/node_process.go index 4ce0997eb60f..f2a9c7ff628d 100644 --- a/tests/fixture/tmpnet/node_process.go +++ b/tests/fixture/tmpnet/node_process.go @@ -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 From da51a7fd73165c35959a0f3c45793b6c425e7b09 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 7 May 2024 12:32:52 -0700 Subject: [PATCH 2/3] fixup: Respond to review comments --- ...hed_process_others.go => detached_process_default.go} | 0 tests/fixture/tmpnet/detached_process_windows.go | 9 ++------- 2 files changed, 2 insertions(+), 7 deletions(-) rename tests/fixture/tmpnet/{detached_process_others.go => detached_process_default.go} (100%) diff --git a/tests/fixture/tmpnet/detached_process_others.go b/tests/fixture/tmpnet/detached_process_default.go similarity index 100% rename from tests/fixture/tmpnet/detached_process_others.go rename to tests/fixture/tmpnet/detached_process_default.go diff --git a/tests/fixture/tmpnet/detached_process_windows.go b/tests/fixture/tmpnet/detached_process_windows.go index 34ee11fcc003..ed7e9908c5d4 100644 --- a/tests/fixture/tmpnet/detached_process_windows.go +++ b/tests/fixture/tmpnet/detached_process_windows.go @@ -5,13 +5,8 @@ package tmpnet -import ( - "os/exec" - "syscall" -) +import "os/exec" func configureDetachedProcess(cmd *exec.Cmd) { - cmd.SysProcAttr = &syscall.SysProcAttr{ - CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, - } + panic("tmpnet deployment to windows is not supported") } From 89cba059c4d99968454f676af52a3a5452a7a9db Mon Sep 17 00:00:00 2001 From: marun Date: Mon, 20 May 2024 16:06:50 -0700 Subject: [PATCH 3/3] Update tests/fixture/tmpnet/detached_process_windows.go Co-authored-by: Stephen Buttolph Signed-off-by: marun --- tests/fixture/tmpnet/detached_process_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixture/tmpnet/detached_process_windows.go b/tests/fixture/tmpnet/detached_process_windows.go index ed7e9908c5d4..bf7ff9a726b4 100644 --- a/tests/fixture/tmpnet/detached_process_windows.go +++ b/tests/fixture/tmpnet/detached_process_windows.go @@ -7,6 +7,6 @@ package tmpnet import "os/exec" -func configureDetachedProcess(cmd *exec.Cmd) { +func configureDetachedProcess(*exec.Cmd) { panic("tmpnet deployment to windows is not supported") }