Skip to content

fix: stabilise flaky TomSelect test helper#2648

Merged
olleolleolle merged 1 commit into
masterfrom
fix/tomselect-flaky-test
Jun 15, 2026
Merged

fix: stabilise flaky TomSelect test helper#2648
olleolleolle merged 1 commit into
masterfrom
fix/tomselect-flaky-test

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Description

Fixes a flaky test in Managing meeting invitations that intermittently failed in CI with:

expected to find css ".ts-dropdown .option" but there were no matches

Root cause

The SelectFromTomSelect test helper had two issues:

  1. ensure_tom_select_initialized hardcoded meeting_organisers as the element ID to manually initialize. This helper is called from pages using meeting_invitations_member (meeting invitations) and meeting_organisers (meeting edit form). When called with the wrong ID, the manual init targeted a non-existent element, creating a race condition with the real init code.

  2. wait: 5 for .ts-dropdown .option was too short for CI environments where the TomSelect AJAX search (/admin/members/search) can take longer than 5 seconds to respond.

Changes

  • Removed ensure_tom_select_initialized — This was a fragile workaround that tried to manually re-initialize TomSelect if the real init hadn't run yet. The real init (jQuery handler in application.js running after CDN script loads) is reliable when given enough time. Manual init with a hardcoded element ID only made things worse.

  • Increased timeout for .ts-dropdown .option from 5s to 10s — Gives CI more time for the AJAX search round-trip.

  • Increased .ts-wrapper wait from 10s to 15s — Extra margin for the CDN script to load and TomSelect to initialize in slow CI environments.

  • Same cleanup applied to remove_from_tom_select for consistency.

Test Plan

  • bundle exec rspec — 1023 examples, 0 failures
  • managing_meeting_invitations_spec.rb passes 5/5 consecutive runs locally
  • meeting_spec.rb passes (also uses select_from_tom_select)

The SelectFromTomSelect helper had two issues causing flaky failures in CI:

1. ensure_tom_select_initialized hardcoded 'meeting_organisers' as the
   element ID, but this helper is also used with 'meeting_invitations_member'.
   Initializing the wrong element created a race condition.

2. wait: 5 for .ts-dropdown .option was too short for CI environments
   where the AJAX search request to /admin/members/search can be slow.

Removed the fragile manual initialization workaround entirely - the real
initialization via application.js + CDN script runs reliably. Increased
timeouts for CI resilience.
@mroderick mroderick marked this pull request as ready for review June 15, 2026 15:09

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚀

@olleolleolle olleolleolle merged commit dbe1ae9 into master Jun 15, 2026
18 checks passed
@olleolleolle olleolleolle deleted the fix/tomselect-flaky-test branch June 15, 2026 18:49
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