-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
@@ -182,7 +182,7 @@ def check_repo_read_access(repo: RepoDefinition): | |||
return False | |||
|
|||
@classmethod | |||
@functools.cache | |||
@functools.lru_cache(maxsize=8) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i trust u
if os.environ.get("CI"): | ||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/app/tests/test_gcloud_credentials.json" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank u sir 🚀
we want to double check lru_cache works the same as cache first
Confirmed that the lru-cache only initializes the repo client once per celery worker process handling an autofix run (same as prior cache) |
There was a problem hiding this 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
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.