librdkafka
librdkafka copied to clipboard
Fix fast leader query back-off
Fix #3690: Metadata leader query timer backoff never applied
Test checks to see that after 1 second 6 triggers occur of an exponentially backed off 10ms timer (you expect triggers at 10 ms, 30, 70, 150, 310 and 630)
I don't immediately see why the rdkafka_timer symbols failed to link in the CI build
Use in code (src/rdtimer.c) unittests to test the private implementation, see for example unittest_broker.
Also make sure the test runs quickly, preferably in under a handful of seconds.
You can run a single unittest by:
TESTS=0000 RD_UT_TEST=backoff make in the tests/ directory.
Thank you. I had neglected the unit test framework. It is a unit test now reduced in duration to one second.
In order for my test to run reliably I had to round up the microsecond-millisecond conversion of sleep time in rd_kafka_timers_run. Otherwise the value is rounded down and I get a 'dribbling' effect of waiting a bit more, a bit more and a tiny bit more still...
sleeptime = rd_kafka_timers_next(rkts, timeout_us,
0 /*no-lock*/);
if (sleeptime > 0) {
cnd_timedwait_ms(&rkts->rkts_cond,
&rkts->rkts_lock,
(int)(sleeptime / 1000) + 1);
}