-
-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print stack traces without panicking on test timeout
- Loading branch information
Showing
4 changed files
with
61 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sigterm_handler_test | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
"testing" | ||
"time" | ||
) | ||
|
||
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() | ||
|
||
// Give any signal handlers registered by rules_go a chance to run. | ||
time.Sleep(1 * time.Second) | ||
|
||
if !called { | ||
t.Fatal("Our handler has not run") | ||
} | ||
} |
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