-
-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go_test: Allow not registering a SIGTERM handler
The rules_go SIGTERM handler causes tests which themselves test responding to SIGTERM to panic and fail.
- Loading branch information
1 parent
55ea579
commit f808fd7
Showing
5 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package sigterm_handler_test | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
func TestRegisterSignalHandler(t *testing.T) { | ||
called := false | ||
var wg sync.WaitGroup | ||
|
||
wg.Add(1) | ||
|
||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGTERM) | ||
|
||
go func() { | ||
switch <-c { | ||
case syscall.SIGTERM: | ||
called = true | ||
wg.Done() | ||
} | ||
}() | ||
|
||
if err := syscall.Kill(os.Getpid(), syscall.SIGTERM); err != nil { | ||
t.Fatalf("Failed to send SIGTERM: %v", err) | ||
} | ||
wg.Wait() | ||
|
||
if !called { | ||
t.Fatal("Our handler has not run") | ||
} | ||
} |