Skip to content

Conversation

@delner
Copy link
Collaborator

@delner delner commented Jan 6, 2026

Problem

Intermittent test failures with WebMock::NetConnectNotAllowedError and "terminated with exception" messages appearing during test runs.

Cause

test_login_with_invalid_api_key created a State without an org_id, which spawns a background login thread. When the VCR cassette was ejected after the test completed, the orphaned thread (still retrying with exponential backoff) would wake up and attempt a real HTTP request, triggering WebMock errors.

Solution

  • Added minitest-stub_any_instance gem for instance method stubbing
  • Created mock_login_in_thread test helper that:
    • Stubs login_in_thread to prevent background thread from spawning
    • Asserts the method would have been called
  • Applied helper to the affected test

This follows the pattern established in PRs #65 and #68 for handling background thread isolation in tests.

@delner delner requested review from clutchski and realark January 6, 2026 15:39
@delner delner self-assigned this Jan 6, 2026
@delner delner added the bug Something isn't working label Jan 6, 2026
Copy link
Contributor

@clutchski clutchski left a comment

Choose a reason for hiding this comment

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

i think i'd just do blocking login in this case, vs adding new dependencies, mocks, etc. but approved, up to you.

@delner delner force-pushed the fix/login_thread_leak_3 branch from 52500e5 to e022304 Compare January 6, 2026 17:04
@delner delner force-pushed the fix/login_thread_leak_3 branch from e022304 to 97ea6e3 Compare January 6, 2026 17:05
@delner
Copy link
Collaborator Author

delner commented Jan 6, 2026

Removed the mock dependency, leveraged blocking_login and isolated other threaded tests in forks.

@delner delner merged commit 3b33286 into main Jan 6, 2026
7 checks passed
@delner delner deleted the fix/login_thread_leak_3 branch January 6, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants