utils: Take monitorShutdownSignal to take an exitFunc which would executed upon error. (#2378)

This hook approach allows program to keep running but being able to handle exiting
of the program in the dynamic way.

Fixes #2377
This commit is contained in:
Harshavardhana
2016-08-06 23:53:10 -07:00
committed by GitHub
parent b23605a2b5
commit 0188cd0b84
3 changed files with 18 additions and 17 deletions
+9 -11
View File
@@ -16,13 +16,10 @@
package main
import (
"testing"
)
import "testing"
// ShutdownCallback simulates a successful exit here, all registered
// shutdown callbacks need to return exitSuccess for this test to succeed
func TestShutdownCallback(t *testing.T) {
// ShutdownCallback simulates a successful and failure exit here.
func TestShutdownCallbackSuccess(t *testing.T) {
// Register two callbacks that return success
registerObjectStorageShutdown(func() errCode {
return exitSuccess
@@ -33,10 +30,11 @@ func TestShutdownCallback(t *testing.T) {
shutdownSignal = make(chan bool, 1)
shutdownSignal <- true
// Start executing callbacks and quit if everything is fine
monitorShutdownSignal()
// Infinite loop here simulates an infinite running program
for {
// Start executing callbacks and exitFunc receives a success.
dummySuccess := func(code int) {
if code != int(exitSuccess) {
t.Fatalf("Expected %d, got %d instead.", code, exitSuccess)
}
}
monitorShutdownSignal(dummySuccess)
}