Bird
0
0

What will be printed by this code snippet?

medium📝 Analysis Q5 of 15
Microservices - Resilience Patterns
What will be printed by this code snippet?
breaker = CircuitBreaker(state='OPEN', failureCount=3, failureThreshold=3)
# After timeout
breaker.state = 'HALF-OPEN'
try:
  call_service()
  breaker.state = 'CLOSED'
  breaker.failureCount = 0
except:
  breaker.state = 'OPEN'
print(breaker.state)

Assuming call_service() succeeds.
ACLOSED
BHALF-OPEN
CFAILED
DOPEN
Step-by-Step Solution
Solution:
  1. Step 1: Understand state transition on success in HALF-OPEN

    When in HALF-OPEN, a successful call resets the breaker to CLOSED and failureCount to zero.
  2. Step 2: Check final state after successful call

    Since call_service() succeeds, breaker.state becomes CLOSED.
  3. Final Answer:

    CLOSED -> Option A
  4. Quick Check:

    Success in HALF-OPEN resets to CLOSED [OK]
Quick Trick: Success in HALF-OPEN resets breaker to CLOSED [OK]
Common Mistakes:
MISTAKES
  • Leaving state as HALF-OPEN after success
  • Assuming state stays OPEN after success
  • Confusing failureCount reset timing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes