Skip to content

Fix a flaky window title test with concurrent select menus - #1824

Merged
tleonhardt merged 1 commit into
mainfrom
fix-flaky-concurrent-select-title-test
Nov 17, 2026
Merged

tleonhardt merged 1 commit into
mainfrom
fix-flaky-concurrent-select-title-test

Conversation

@tleonhardt

Copy link
Copy Markdown
Member

test_instance_titles_do_not_cross_between_concurrent_select_menus failed on ubuntu / Python 3.14 in CI
for #1815, on a commit which passed the same job in a second run:

AssertionError: assert '\x1b]2;B\x07' in '\x1b[?2004h\x1b[?1l\x1b[?25l...'

Cause

The test sets the title B while the second menu is running, waits for the first menu to finish, and
then sets B active. A title set during a prompt is written by a callback on that prompt's event loop,
and a title set before the callback runs replaces it, as set_window_title() documents. Nothing in the
test made the second menu's loop run between the two calls. When that thread was not scheduled in
time, only B active was written and the assertion that B was written failed.

This is a race in the test. cmd2 behaves as documented, and no library code changes.

Fix

After setting B, queue a callback on the second menu's loop and wait for it. Callbacks run in order,
so the title has been written by then.

Verification

Running the test 400 times per round on 14 xdist workers with every CPU saturated:

rounds result
before 3 13 failures in 1,200 runs
after 5 0 failures in 2,000 runs

Every failure before the fix had B active in the second stream and no B, matching the CI failure.
Without load the test passed 400 of 400 times either way.

test_instance_titles_do_not_cross_between_concurrent_select_menus sets the
title "B" while the second menu is running and then, once the first menu
has finished, "B active". A title set during a prompt is written by a
callback on the prompt's event loop, and a title set before that callback
runs replaces it. Nothing made the second menu's loop run before "B active"
was set, so under load "B" was never written and the test failed.

Wait for the second menu's loop to get past the callback before going on.
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (fa81c19) to head (c581a5b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1824   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files          23       23           
  Lines        6664     6664           
=======================================
  Hits         6648     6648           
  Misses         16       16           
Flag Coverage Δ
unittests 99.75% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@tleonhardt
tleonhardt merged commit e5811a3 into main Nov 17, 2026
32 checks passed
@tleonhardt
tleonhardt deleted the fix-flaky-concurrent-select-title-test branch November 17, 2026 03:59
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