]> git.ipfire.org Git - thirdparty/rspamd.git/commit
[Test] upstream: deterministic SRV rate-window test via libev fake clock 6030/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 9 May 2026 13:38:18 +0000 (14:38 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 9 May 2026 13:38:18 +0000 (14:38 +0100)
commit7af41afd17da3d12fd679d54de3f84908f4d91f1
treecc8b509e1f39694f7f4f31f80756bb6906b5eee8
parent1f83bd9676f581f97b348079416008fbf4e45d53
[Test] upstream: deterministic SRV rate-window test via libev fake clock

Switch rspamd_upstream_fail's rate-window timestamp from
rspamd_get_ticks(FALSE) to a new rspamd_upstream_now_fresh helper that
calls ev_now_update_if_cheap then ev_now. Multiple fail() calls in a
single loop iteration now see fresh times, and tests can drive virtual
time through the libev hook without sleeping.

  * rspamd_upstream_now / rspamd_upstream_now_fresh helpers hoisted to
    the top of upstream.c with a short comment about why ev_now matters
    (loop-cached time = tests can drive it; production correctness wart
    of mixed time sources goes away).
  * rspamd_upstream_ctx_set_event_loop_for_test: install a loop on
    upstream_ctx without going through rspamd_upstreams_library_config
    (which needs a full rspamd_config).
  * rspamd_test::fake_clock RAII helper installs the libev hook,
    advances virtual time, and resyncs the loop on construct/destroy.

The "error budget is per member" SRV test drops g_usleep(1000) and the
error_time = 0.002 s macOS-jitter workaround; uses error_time = 1.0 s,
max_errors = 4, and clk.advance(0.1) between fails. Test runs in 80 ms
and is fully deterministic.
src/libutil/upstream.c
src/libutil/upstream_internal.h
test/rspamd_cxx_unit_upstream_srv.hxx
test/rspamd_test_fake_time.hxx [new file with mode: 0644]