Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bzltestutil: restore timeout signal handler #3929

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions go/tools/builders/generate_test_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,23 @@ func main() {
// we set -test.timeout according to the TEST_TIMEOUT, we need to ignore the signal so the test has
// time to properly produce the output (e.g. stack trace). It will be killed by Bazel after the grace
// period (15s) expires.
//
// If TEST_TIMEOUT is not set (e.g., when the test binary is run by Delve for debugging), we don't
// ignore SIGTERM so it can be properly terminated.
signal.Ignore(syscall.SIGTERM)
// ignore SIGTERM so it can be properly terminated. (1)
// We do not panic (like native go test does) because users may legitimately want to use SIGTERM
// in tests.
//
// signal.Notify is used to ensure that there is a no-op signal handler registered.
// Avoid using signal.Ignore here: despite the name, it's only used to unregister handlers that
// were previously registered by signal.Notify. See (2) for more information.
//
// (1): https://github.com/golang/go/blob/e816eb50140841c524fd07ecb4eaa078954eb47c/src/testing/testing.go#L2351
// (2): https://github.com/bazelbuild/rules_go/pull/3929
c := make(chan os.Signal, 1)
fmeum marked this conversation as resolved.
Show resolved Hide resolved
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
}()
}

{{if not .TestMain}}
Expand Down