|
1 | 1 | package builder_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "github.com/golang/mock/gomock"
|
5 | 6 | "github.com/pkg/errors"
|
6 | 7 | "github.com/redhat-developer/service-binding-operator/apis/binding/v1alpha1"
|
@@ -82,6 +83,27 @@ var _ = Describe("Pipeline", func() {
|
82 | 83 | Expect(retry).To(BeTrue())
|
83 | 84 | })
|
84 | 85 |
|
| 86 | + It("should retry processing if panic occurred in a handler", func() { |
| 87 | + err := fmt.Errorf("panic occurred: %v", "foo") |
| 88 | + |
| 89 | + h1 := defHandler() |
| 90 | + h1.EXPECT().Handle(ctx) |
| 91 | + h2 := func(c pipeline.Context) { |
| 92 | + panic("foo") |
| 93 | + } |
| 94 | + h3 := defHandler() |
| 95 | + p := builder.Builder().WithContextProvider(&ctxProvider{ctx: ctx}).WithHandlers(h1, pipeline.HandlerFunc(h2), h3).Build() |
| 96 | + |
| 97 | + ctx.EXPECT().RetryProcessing(err) |
| 98 | + ctx.EXPECT().Close().Return(nil) |
| 99 | + ctx.EXPECT().FlowStatus().Return(pipeline.FlowStatus{}) |
| 100 | + ctx.EXPECT().FlowStatus().Return(pipeline.FlowStatus{Retry: true, Stop: true, Err: err}) |
| 101 | + |
| 102 | + retry, rerr := p.Process(&v1alpha1.ServiceBinding{}) |
| 103 | + Expect(rerr).To(Equal(err)) |
| 104 | + Expect(retry).To(BeTrue()) |
| 105 | + }) |
| 106 | + |
85 | 107 | It("should stop without retry and error and propagate that back to caller", func() {
|
86 | 108 | h1 := defHandler()
|
87 | 109 | h1.EXPECT().Handle(ctx)
|
@@ -116,6 +138,32 @@ var _ = Describe("Pipeline", func() {
|
116 | 138 | Expect(err).To(Equal(err))
|
117 | 139 | Expect(retry).To(BeTrue())
|
118 | 140 | })
|
| 141 | + |
| 142 | + It("should retry processing if panic occurs when closing context", func() { |
| 143 | + var err = fmt.Errorf("panic occurred: %v", "foo") |
| 144 | + h1 := defHandler() |
| 145 | + h1.EXPECT().Handle(ctx) |
| 146 | + p := builder.Builder().WithContextProvider(&ctxProvider{ctx: ctx}).WithHandlers(h1).Build() |
| 147 | + |
| 148 | + ctx.EXPECT().Close().DoAndReturn(func() { panic("foo") }) |
| 149 | + ctx.EXPECT().FlowStatus().Return(pipeline.FlowStatus{}).Times(1) |
| 150 | + |
| 151 | + retry, perr := p.Process(&v1alpha1.ServiceBinding{}) |
| 152 | + Expect(perr).To(Equal(err)) |
| 153 | + Expect(retry).To(BeTrue()) |
| 154 | + }) |
| 155 | + |
| 156 | + It("should retry processing if panic occurs when calling context provider", func() { |
| 157 | + var err = fmt.Errorf("panic occurred: %v", "foo") |
| 158 | + h1 := defHandler() |
| 159 | + provider := mocks.NewMockContextProvider(mockCtrl) |
| 160 | + provider.EXPECT().Get(&v1alpha1.ServiceBinding{}).DoAndReturn(func(b interface{}) { panic("foo") }) |
| 161 | + p := builder.Builder().WithContextProvider(provider).WithHandlers(h1).Build() |
| 162 | + |
| 163 | + retry, perr := p.Process(&v1alpha1.ServiceBinding{}) |
| 164 | + Expect(perr).To(Equal(err)) |
| 165 | + Expect(retry).To(BeTrue()) |
| 166 | + }) |
119 | 167 | })
|
120 | 168 |
|
121 | 169 | type ctxProvider struct {
|
|
0 commit comments