Skip to main content

Overview

The Loop block signals the pipeline to jump back to a previous block, allowing you to repeat portions of your test. Useful for retry logic, polling, or testing iterative agent behaviors.

Configuration

Input Parameters

Loop accepts any inputs and passes them through. This allows you to carry data through loop iterations.

Output Fields

Loop outputs special control fields: Plus all input fields are passed through.

How It Works

  1. Pipeline executes blocks in sequence
  2. When Loop executes, it evaluates the condition (if provided)
  3. If condition is true (or no condition), returns _loopTo, _maxLoops, and _shouldLoop: true
  4. Pipeline jumps back to the target block
  5. Blocks between target and Loop execute again
  6. Loop counter increments each iteration
  7. When condition becomes false or maxIterations reached, loop stops
Example flow:

Conditional Logic

Loop supports conditional evaluation to control when looping occurs. The condition parameter accepts an object with:

Available Operators

  • Equality: equals, notEquals
  • Numeric: gt, gte, lt, lte
  • String/Array: contains, notContains, minLength, maxLength
  • Pattern: matches, notMatches
  • Type: isNull, isNotNull, isDefined, isUndefined
  • Boolean: isTrue, isFalse
  • Empty: isEmpty, isNotEmpty

Condition Examples

Loops while response.status is not 200.
Loops while job.progress is less than 100.
Loops while data.ready is false.

Examples

Basic Loop

This loops back to “attempt” up to 5 times.

Conditional Loop (Polling)

How it works: The loop checks status.state each iteration. If it’s not “completed”, it loops back to checkStatus. When the status becomes “completed” (or maxIterations is reached), the loop stops and assertions verify the final state.

Retry Until Success

This retries the request up to 3 times, stopping as soon as it gets a 200 status.

Threshold Checking

Keeps checking until the score reaches at least 0.8, or gives up after 5 attempts.

Multi-Step Loop

Loop Counter

The pipeline tracks loop iterations in context:
This counter is per-target, so multiple loops can coexist.

Common Patterns

Polling Until Ready

How it works:
  1. Checks job status
  2. Parses response
  3. Loops back if not complete
  4. Stops after 20 attempts or when complete

Retry Failed Requests

Agent Iteration Testing

Loop Limits

Default limit: 10 iterations per loop target Maximum safe limit: 100 iterations Why limits exist:
  • Prevent infinite loops
  • Avoid test timeouts
  • Protect against configuration errors
Override the limit:

Best Practices

Don’t rely on defaults. Set appropriate limits:
Perfect for checking async job status:
Use assertions to verify final state after looping:
Avoid loops within loops - use separate tests instead:

Limitations

Current limitations:
  1. Single target - Can only loop to one block at a time
  2. Forward loops not allowed - Can only loop backwards to previous blocks
  3. No loop nesting - Cannot reliably nest loops within loops
Best practices:
  • Use conditional logic to control loop execution
  • Set reasonable maxIterations to prevent timeouts
  • Use assertions to verify final state after looping
  • For complex scenarios, split into separate tests

Full Example

Tips

Currently, Loop doesn’t have built-in delays. For polling, consider test structure or external delays.
Check context for loop count if needed:
Retry flaky operations automatically:

When to Use

Use Loop when:
  • Polling for async operation completion
  • Retrying failed requests
  • Testing iterative agent behaviors
  • Checking status until ready
Don’t use when:
  • Simple sequential flow is sufficient
  • Need complex conditional logic (use separate tests)
  • Testing requires precise timing control

Next Steps

Pipelines

Learn about pipeline execution

Data Flow

Understand data passing between blocks