MCPcopy Create free account
hub / github.com/The-Pocket/PocketFlow-Go / TestNodeRetryFailureWithFallback

Function TestNodeRetryFailureWithFallback

pocketflow_test.go:224–245  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

222}
223
224func 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
247func TestNodeRetryFailureWithoutFallback(t *testing.T) {
248 execCount := 0

Callers

nothing calls this directly

Calls 4

SetFallbackMethod · 0.80
SetExecMethod · 0.80
RunMethod · 0.65
SetRetryMethod · 0.45

Tested by

no test coverage detected