Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(autofix): Add more vcr-based tests for autofix scenarios #1681

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jennmueng
Copy link
Member

@jennmueng jennmueng commented Jan 6, 2025

The test cases for autofix tasks now are thorough and run the complete workflow.

Reimplements test cases for code/diff changes and user messages/interjections with no mocking.

@@ -182,7 +182,7 @@ def check_repo_read_access(repo: RepoDefinition):
return False

@classmethod
@functools.cache
@functools.lru_cache(maxsize=8)
Copy link
Member Author

@jennmueng jennmueng Jan 6, 2025

Choose a reason for hiding this comment

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

@functools.cache was breaking vcr test cases as it was maintaining the cache across multiple test cases rather than cleaning it

  • @functools.cache maintains its cache for the entire lifetime of the Python process
  • @functools.lru_cache creates a new cache instance each time the decorated function is redefined, which typically happens for each test module

This means that lru_cache naturally provides better test isolation out of the box, even without explicit cache clearing. This is one of the less-documented but important differences between the two decorators.

Copy link
Member

Choose a reason for hiding this comment

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

Is cache clearing not feasible instead? This sounds like it would cause more repo_client initialization calls and add lag back in some cases

Copy link
Member Author

@jennmueng jennmueng Jan 6, 2025

Choose a reason for hiding this comment

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

lru cache in prod in this use case should work exactly the same as the existing cache with a limit instead of being unbounded. we can add cache clearing but we'll need to explicitly define that for test cases, and for the sake of unit testing the expected behavior is each test case is independent anyways so this removes an unexpected behavior

the limit of 8 was set instead of an infinite size as I don't foresee there being more than 8 repos in an autofix run

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking about the entire Python process vs. decorated function is redefined. In Autofix's context, when do new processes start? And when is the function redefined? Are they the same or different?

Copy link
Member Author

Choose a reason for hiding this comment

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

in a prod environment it should be equivalent as the function/class is defined when the process starts, the only difference is in testing environments

Copy link
Member Author

Choose a reason for hiding this comment

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

so in autofix prod, each celery process has its own cache for either the lru cache or cach method and they fundamentally would work the same

Copy link
Member

Choose a reason for hiding this comment

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

ok i trust u

@jennmueng jennmueng requested a review from roaga January 6, 2025 19:46
@jennmueng jennmueng marked this pull request as ready for review January 6, 2025 19:47
@jennmueng jennmueng requested a review from a team as a code owner January 6, 2025 19:47
Comment on lines +27 to +28
if os.environ.get("CI"):
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/app/tests/test_gcloud_credentials.json"
Copy link
Member

Choose a reason for hiding this comment

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

oh? does this fix the need to comment this line out locally?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah this is so we are actually able to call vertex locally when making the vcr cassettes

@roaga roaga self-requested a review January 6, 2025 20:44
roaga
roaga previously approved these changes Jan 6, 2025
Copy link
Member

@roaga roaga left a comment

Choose a reason for hiding this comment

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

Thank u sir 🚀

@roaga roaga dismissed their stale review January 6, 2025 21:23

we want to double check lru_cache works the same as cache first

@jennmueng
Copy link
Member Author

Confirmed that the lru-cache only initializes the repo client once per celery worker process handling an autofix run (same as prior cache)

Copy link
Member

@roaga roaga left a comment

Choose a reason for hiding this comment

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

Thank you for double checking

Though RIP on the cassette merge conflicts

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