Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions tests/test_end_to_end_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,15 @@ def test_concurrent_operations_workflow(self, mock_applications, mock_homebrew_c
"""Test concurrent operations workflow."""
import threading

mock_app_tuples = [("Firefox", "110.0"), ("Google Chrome", "110.0.5481.177"), ("Visual Studio Code", "1.74.0")]
results = []

def run_versiontracker():
with mock.patch("sys.argv", ["versiontracker", "--apps"]):
result = versiontracker_main()
results.append(result)
# Patch the handler's local import (imported by value, so source-module mock doesn't intercept)
with mock.patch("versiontracker.handlers.app_handlers._get_apps_data", return_value=mock_app_tuples):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply _get_apps_data patch once outside worker threads

Patching versiontracker.handlers.app_handlers._get_apps_data inside each thread is racy: unittest.mock.patch stores/restores the target value per context, so when one thread exits its with block it can restore the real function while other threads are still running. In that window, another thread can call the real _get_apps_data (and trigger system_profiler), reintroducing the same timeout flake this commit is trying to fix. Patch this symbol once around thread startup/join so all workers see a stable mock for the full test duration.

Useful? React with 👍 / 👎.

with mock.patch("sys.argv", ["versiontracker", "--apps"]):
result = versiontracker_main()
results.append(result)

# Run multiple instances concurrently
threads = []
Expand All @@ -310,7 +313,7 @@ def run_versiontracker():

# Wait for all to complete
for thread in threads:
thread.join(timeout=10)
thread.join(timeout=30)

# All should succeed
assert len(results) == 3
Expand Down
Loading