1
0
Fork 0

Fix panic in k8s loadIngresses

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-12-08 13:32:52 +01:00
parent be362f0d9f
commit 5a67d0ac84
No known key found for this signature in database
GPG key ID: D808B4C167352E59
5 changed files with 29 additions and 5 deletions

View file

@ -152,11 +152,10 @@ func OperationWithRecover(operation backoff.Operation) backoff.Operation {
return func() (err error) {
defer func() {
if res := recover(); res != nil {
defaultRecoverGoroutine(err)
defaultRecoverGoroutine(res)
err = fmt.Errorf("Panic in operation: %s", err)
}
}()
err = operation()
return nil
return operation()
}
}

View file

@ -1,11 +1,22 @@
package safe
import (
"fmt"
"github.com/cenk/backoff"
"testing"
)
func TestOperationWithRecover(t *testing.T) {
operation := func() error {
return nil
}
err := backoff.Retry(OperationWithRecover(operation), &backoff.StopBackOff{})
if err != nil {
t.Fatalf("Error in OperationWithRecover: %s", err)
}
}
func TestOperationWithRecoverPanic(t *testing.T) {
operation := func() error {
panic("BOOM")
}
@ -14,3 +25,13 @@ func TestOperationWithRecover(t *testing.T) {
t.Fatalf("Error in OperationWithRecover: %s", err)
}
}
func TestOperationWithRecoverError(t *testing.T) {
operation := func() error {
return fmt.Errorf("ERROR")
}
err := backoff.Retry(OperationWithRecover(operation), &backoff.StopBackOff{})
if err == nil {
t.Fatalf("Error in OperationWithRecover: %s", err)
}
}