Your issue involves multiple interconnected problems. Let me break down the complete solution:
State Machine Configuration: Rally’s TestCaseResult state machine requires three mandatory fields for completion: Verdict, Build, and Date. Your original code was missing Build. Additionally, the state machine has validation rules that prevent transitions if the TestCase parent is in certain states (Archived, Deprecated). Verify your test cases aren’t in these states:
test_case = rally.get('TestCase', fetch=['ScheduleState'])
if test_case.ScheduleState in ['Archived', 'Deprecated']:
# Cannot update execution status
Webhook Event Handlers: The async nature of webhooks means you can’t rely on immediate state changes. Implement a polling mechanism after your API call:
// Pseudocode - Verification loop:
1. Submit TestCaseResult update via PUT request
2. Wait 2-3 seconds for webhook processing
3. GET the TestCaseResult object and check Verdict field
4. If still 'In Progress', retry update with exponential backoff
5. Log failures after 3 retry attempts
Permission Validation: Your API user needs workspace-level permissions, not just project-level. Navigate to Setup > Workspace > Permissions and verify the API key has ‘Workspace Admin’ or ‘Editor’ role with ‘Modify All’ checked for TestCaseResult objects. Project-level permissions aren’t sufficient for state transitions.
Test Result Mapping: The 15% failure rate suggests orphaned relationships. Implement a health check before updates:
result_data = {
"TestCaseResult": {
"TestCase": test_case_ref, # Re-establish link
"Verdict": "Pass",
"Build": build_number,
"Date": datetime.now().isoformat(),
"Tester": user_ref # Required for audit trail
}
}
The Tester field is often overlooked but required for proper state transitions in Rally 2023+. Without it, Rally’s validation engine rejects the update silently.
For your reporting pipeline, implement a cleanup job that runs hourly to detect stuck executions and force-complete them with a ‘Blocked’ verdict. This prevents dashboard pollution while you fix the root cause. The combination of adding all required fields, verifying permissions, and implementing retry logic should resolve 99%+ of your stuck status issues.