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
Parameter | Type | Default | Description |
---|---|---|---|
target | string/number | required | Block ID or index to loop back to |
maxIterations | number | 10 | Maximum iterations to prevent infinite loops |
condition | object | optional | Condition object to evaluate. Loop continues while condition is true. If omitted, loops unconditionally. |
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:Field | Type | Description |
---|---|---|
_loopTo | string/number | Target block to loop back to (only when looping) |
_maxLoops | number | Maximum iterations allowed (only when looping) |
_shouldLoop | boolean | Whether the loop condition was met and looping should occur |
How It Works
- Pipeline executes blocks in sequence
- When Loop executes, it evaluates the condition (if provided)
- If condition is true (or no condition), returns
_loopTo
,_maxLoops
, and_shouldLoop: true
- Pipeline jumps back to the target block
- Blocks between target and Loop execute again
- Loop counter increments each iteration
- When condition becomes false or maxIterations reached, loop stops
Conditional Logic
Loop supports conditional evaluation to control when looping occurs. Thecondition
parameter accepts an object with:
Field | Type | Description |
---|---|---|
path | string | Path to value in DataBus (e.g., "response.status" ) |
operator | string | Comparison operator (see below) |
value | any | Expected value to compare against |
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
response.status
is not 200.
job.progress
is less than 100.
data.ready
is false.
Examples
Basic Loop
Conditional Loop (Polling)
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
Threshold Checking
Multi-Step Loop
Loop Counter
The pipeline tracks loop iterations in context:Common Patterns
Polling Until Ready
- Checks job status
- Parses response
- Loops back if not complete
- 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
Best Practices
Always Set Reasonable maxIterations
Always Set Reasonable maxIterations
Don’t rely on defaults. Set appropriate limits:
Use Loop for Polling
Use Loop for Polling
Perfect for checking async job status:
Combine with Assertions
Combine with Assertions
Use assertions to verify final state after looping:
Don't Nest Loops
Don't Nest Loops
Avoid loops within loops - use separate tests instead:
Limitations
Current limitations:- Single target - Can only loop to one block at a time
- Forward loops not allowed - Can only loop backwards to previous blocks
- No loop nesting - Cannot reliably nest loops within loops
- 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
Add Delays Between Iterations
Add Delays Between Iterations
Currently, Loop doesn’t have built-in delays. For polling, consider test structure or external delays.
Monitor Loop Counter
Monitor Loop Counter
Check context for loop count if needed:
Use for Flaky Tests
Use for Flaky Tests
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
- Simple sequential flow is sufficient
- Need complex conditional logic (use separate tests)
- Testing requires precise timing control