Skip to content

test(qwp): deflake close-lifecycle interrupt tests - #79

Open
mtopolnik wants to merge 1 commit into
mainfrom
mt_fix-test
Open

test(qwp): deflake close-lifecycle interrupt tests#79
mtopolnik wants to merge 1 commit into
mainfrom
mt_fix-test

Conversation

@mtopolnik

Copy link
Copy Markdown
Contributor

What

Fixes flakiness in the two QuestDBImplCloseLifecycleTest tests that check close() stays bounded under repeated interrupts (the query and the sender variant). On a busy CI machine they could fail with:

close left its creation wait before the interrupt storm landed twice; interrupts landed: 1

even though the product code honored its deadline exactly as intended.

Why it flaked

Each test used a background thread to interrupt the closing thread, then waited to observe at least two interrupts land while close() was still waiting. That wait read hasCreationWaiterForTesting(), which briefly reports false every time an interrupt wakes the waiting thread before it goes back to sleep. On a busy machine the background thread was slow to run, and the wait caught that brief gap after a single interrupt, so it failed while the product was correct.

A previous change raised the close budget from 100ms to 1s, which made this rarer but did not remove the race.

Fix

  • The test thread now delivers one interrupt itself while close() is definitely still waiting. This guarantees an interrupt lands during the wait, so the test's existing "close restored the interrupt flag" assertion is reliable (the product restores that flag only when it caught an interrupt during the wait).
  • A background thread keeps interrupting through the join. That is the part that would actually catch a real bug: if an interrupt reset the deadline, close() would never return and the join would time out.
  • Removed the fragile "wait for two interrupts to land" helper and a redundant counter assertion.

Behavior of the product code is unchanged; this is a test-only change.

Test plan

  • mvn -pl core test -Dtest=QuestDBImplCloseLifecycleTest passes (6/6).
  • Ran the two interrupt tests 5 extra times back to back, green each time, ~2.3s per run.

The two "close is bounded under repeated interrupts" tests (query and
sender) could fail on a busy CI machine with "close left its creation
wait before the interrupt storm landed twice; interrupts landed: 1",
even though the product code was correct.

The tests used a background thread to interrupt the closing thread and
then waited to observe at least two interrupts land while close() was
still waiting. That wait read hasCreationWaiterForTesting(), which
briefly reports false every time an interrupt wakes the waiting thread
before it goes back to sleep. On a busy machine the background thread
was slow and the wait caught that brief gap after a single interrupt,
so it failed while the product honored its deadline exactly as intended.

Make the check reliable: the test thread now delivers one interrupt
itself while close() is definitely still waiting, which guarantees an
interrupt lands during the wait (close restores the interrupt flag only
when it caught one, and the test already asserts that flag). A
background thread keeps interrupting through the join, which is the part
that would actually catch a bug, since a reset deadline would make
close() hang and time out the join. Removed the fragile "wait for two
to land" helper and a redundant counter assertion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant