Skip to content

fix: replace blind sleep in TomSelect helper with adaptive Capybara wait#2704

Open
mroderick wants to merge 2 commits into
masterfrom
fix/tom-select-dropdown-flake
Open

fix: replace blind sleep in TomSelect helper with adaptive Capybara wait#2704
mroderick wants to merge 2 commits into
masterfrom
fix/tom-select-dropdown-flake

Conversation

@mroderick

@mroderick mroderick commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Problem

Two timing issues in TomSelect test interactions were producing CI flakes:

  1. select_from_tom_select helper — used a blind sleep 0.5 between typing the first 3 chars (triggering shouldLoad + AJAX) and the remaining chars. Under CI resource contention, the 300ms debounce + AJAX could exceed 0.5s. Observed on PR fix: move EventHelper from app/helpers to app/models/concerns #2702 (group 5, seed 64177):

    expected to find css ".ts-dropdown .option" but there were no matches
    
  2. tom_select_member_lookup_spec.rb — same sleep 0.5 between 2-char and remainder sends (but this sleep was doing nothing: shouldLoad requires >=3 chars, so the 2-char first send never triggers AJAX). Also had tight wait: 5 waits for AJAX-driven .ts-dropdown .option.

Fix

Helper (select_from_tom_select): Replace sleep 0.5 with an adaptive have_css wait (15s) for the dropdown to render after the initial 3-char search. Added text: matcher on the second dropdown wait to confirm refined search results are rendered.

Spec (tom_select_member_lookup_spec.rb): Remove the dead sleep 0.5. Bump all TomSelect-related waits from 5s to 15s for consistency with the helper.

Verification

  • CI failure seed (64177): passes
  • Full suite: 1106 examples, 0 failures
  • Parallel execution (make test): 1106 examples, 0 failures
  • All TomSelect tests pass across multiple random seeds

The select_from_tom_select helper used a blind sleep 0.5 between typing
the first 3 characters and the remaining ones. In CI under resource
contention, the 300ms TomSelect debounce + AJAX fetch could exceed this
fixed wait, causing the dropdown never to appear.

Replace the sleep with an adaptive Capybara have_css wait (15s timeout)
for the .ts-dropdown .option to appear after the initial search trigger.
This gives slow CI environments enough time while fast environments don't
waste a fixed wait.
…p spec

The sleep 0.5 between typing 'Ja' and 'ne' was doing nothing — TomSelect's
shouldLoad requires >= 3 characters, so no AJAX fires on the initial 2-char
input. The real wait is for the AJAX response after the full query is typed.

Bumped all TomSelect-related waits from 5s to 15s for consistency with the
shared select_from_tom_select helper, reducing flake risk under CI load.
@mroderick mroderick marked this pull request as ready for review July 14, 2026 09:15
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