(t *testing.T)
| 222 | } |
| 223 | |
| 224 | func TestNodeRetryFailureWithFallback(t *testing.T) { |
| 225 | execCount := 0 |
| 226 | fallbackCalled := false |
| 227 | node := pf.NewNode(). |
| 228 | SetRetry(2, 1*time.Millisecond). // Use time.Millisecond |
| 229 | SetExec(func(ctx *pf.PfContext, params map[string]any, prepResult any) (any, error) { |
| 230 | execCount++ |
| 231 | return nil, fmt.Errorf("permanent failure %d", execCount) // Always fail |
| 232 | }). |
| 233 | SetFallback(func(ctx *pf.PfContext, params map[string]any, prepResult any, lastErr error) (any, error) { |
| 234 | fallbackCalled = true |
| 235 | assert.ErrorContains(t, lastErr, "permanent failure 2") |
| 236 | return "fallback_success", nil // Fallback succeeds |
| 237 | }) |
| 238 | ctx := pf.WithParam(context.Background(), nil) |
| 239 | |
| 240 | action, err := node.Run(ctx) |
| 241 | require.NoError(t, err) |
| 242 | assert.Equal(t, 2, execCount, "Exec should have been called 2 times") |
| 243 | assert.True(t, fallbackCalled, "Fallback should have been called") |
| 244 | assert.Equal(t, pf.DefaultAction, action) // Default post action |
| 245 | } |
| 246 | |
| 247 | func TestNodeRetryFailureWithoutFallback(t *testing.T) { |
| 248 | execCount := 0 |
nothing calls this directly
no test coverage detected