Skip to content

fix(pooling): make active-connection assertions race-free#103

Merged
dkasimovskiy merged 3 commits into
masterfrom
fix/connection-pool-flaky-tests-min-changes
Jun 26, 2026
Merged

fix(pooling): make active-connection assertions race-free#103
dkasimovskiy merged 3 commits into
masterfrom
fix/connection-pool-flaky-tests-min-changes

Conversation

@dkasimovskiy

@dkasimovskiy dkasimovskiy commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Что сделано

Проверка на количество активных соединений в интеграционных тестах tarantool-pooling теперь дожидаются стабилизации счётчика на стороне Tarantool, а не читают его один раз.

Зачем

box.stat.net().CONNECTIONS.current обновляется асинхронно. Старый getActiveConnectionsCount делал единственный executeCommandDecoded сразу после старта клиентов.
Под нагрузкой CI значение кол-ва активных соединений часто оказывалось на одно больше или меньше реального, как следствие ConnectionPoolReconnectsTest периодически падал с ошибкой expected: but was: <count1 - 1> (или ниже).

Изменения

  • BasePoolTest#getActiveConnectionsCount теперь выполняет короткий ограниченный Lua-цикл: перечитывает счётчик и возвращает значение, только когда два чтения подряд совпали. Если счётчик всё время меняется, через 50 × 50 миллисекунд возвращается последнее значение.
  • Новый хелпер BasePoolTest#waitForActiveConnections(tt, expected) для тестов, которым нужно точное кол-во активных соединений.
  • В ConnectionPoolReconnectsTest два assertEquals(count1, getActiveConnectionsCount(tt)) заменены на waitForActiveConnections(tt, count1).

I haven't forgotten about:

  • Tests
  • Changelog
  • Documentation
    • JavaDoc was written
  • Commit messages comply with the guideline
  • Cleanup the code for review. See checklist

Related issues:

@dkasimovskiy dkasimovskiy force-pushed the fix/connection-pool-flaky-tests-min-changes branch from 17582df to d30ba39 Compare June 25, 2026 08:57
box.stat.net().CONNECTIONS.current is updated asynchronously by the IProto
worker, so reading it once right after starting clients can return a stale
value and flake ConnectionPoolReconnectsTest. Replace the single read in
BasePoolTest#getActiveConnectionsCount with a bounded Lua poll that waits
until the counter stops changing, and add waitForActiveConnections helper
for tests that need to assert a specific count.

Test-only change.
Documents the fix for flaky active-connection assertions under Unreleased > Bug fixes.
@dkasimovskiy dkasimovskiy force-pushed the fix/connection-pool-flaky-tests-min-changes branch from d30ba39 to 5f90d0f Compare June 25, 2026 08:59
@dkasimovskiy dkasimovskiy changed the title fix(pooling): fix tests only fix(pooling): make active-connection assertions race-free Jun 25, 2026
@dkasimovskiy dkasimovskiy marked this pull request as ready for review June 25, 2026 09:47
+ " for i = 1, 50 do"
+ " require('fiber').sleep(0.05);"
+ " local cur = box.stat.net().CONNECTIONS.current;"
+ " if cur == last then return cur - 1 end;"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо сделать по другому немного: надо сделать так, чтобы этот счётчик не менял своё значение N раз. Например, если он 5 раз выдаёт одно и то же значение - значит, это количество соединений устаканилось и его можно использовать. И паузы побольше

Address PR #103 review: the 2-reads-at-50ms heuristic can still land on
a transitional value while the IProto worker is mid-batch. Require 5
consecutive equal reads at 100ms intervals (5x100ms=500ms worst case
before return; 100-iter safety net = 10s).

Also collapse waitForActiveConnections to a single assert — the Lua poll
already waits up to 10s, so the outer waitFor wrapper was redundant.
@dkasimovskiy dkasimovskiy merged commit b902bfa into master Jun 26, 2026
14 of 16 checks passed
@dkasimovskiy dkasimovskiy deleted the fix/connection-pool-flaky-tests-min-changes branch June 26, 2026 06:07
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