Skip to content

test: keep Redis fail_max concurrency test from timing out mid-run - #107

Merged
danielfm merged 1 commit into
danielfm:mainfrom
Xeonacid:test/redis-fail-max-timeout
Sep 25, 2026
Merged

danielfm merged 1 commit into
danielfm:mainfrom
Xeonacid:test/redis-fail-max-timeout

Conversation

@Xeonacid

Copy link
Copy Markdown
Contributor

CircuitRedisStorage persists opened_at as a whole-second Unix timestamp via calendar.timegm()/time.gmtime(), so a reset_timeout of 1 second can elapse anywhere from nearly 0s to 1s after the circuit opens.

CircuitBreakerRedisConcurrencyTestCase issues 3 threads x 2000 guarded calls with fail_max=3000. After the breaker trips, the remaining calls still hit Redis. On slower hosts the truncated timeout expires, the breaker goes half-open, the trial call fails, and fail_counter is incremented again. Those extra counts are unrelated to the concurrent INCR overshoot the assertion allows (fail_max + num_threads) and fail the test, e.g. assert 3005 < 3000 + 3.

On a riscv64 host this test takes ~9-10s for the test body and ~14s for the pytest session. Raise this class's reset_timeout to 20s so the circuit stays open for the rest of the run with a small margin. test_half_open_thread_safety creates its own breaker and is unchanged.

CircuitRedisStorage persists opened_at as a whole-second Unix timestamp
via calendar.timegm()/time.gmtime(), so a reset_timeout of 1 second can
elapse anywhere from nearly 0s to 1s after the circuit opens.

CircuitBreakerRedisConcurrencyTestCase issues 3 threads x 2000 guarded
calls with fail_max=3000. After the breaker trips, the remaining calls
still hit Redis. On slower hosts the truncated timeout expires, the
breaker goes half-open, the trial call fails, and fail_counter is
incremented again. Those extra counts are unrelated to the concurrent
INCR overshoot the assertion allows (fail_max + num_threads) and fail
the test, e.g. assert 3005 < 3000 + 3.

On a riscv64 host (centiskorch) this test takes ~9-10s for the test
body and ~14s for the pytest session. Raise this class's reset_timeout
to 20s so the circuit stays open for the rest of the run with a small
margin. test_half_open_thread_safety creates its own breaker and is
unchanged.

This is the same rounding already documented by test_successful_after_timeout,
which sleeps 2s "since redis rounds to a second".
@danielfm danielfm self-assigned this Sep 25, 2026
@danielfm

Copy link
Copy Markdown
Owner

Thanks!

@danielfm
danielfm merged commit 2b0b965 into danielfm:main Sep 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants