-
Notifications
You must be signed in to change notification settings - Fork 8
Resolve cyclic imports in e2e tests #172
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
Conversation
043f6e7
to
93baf39
Compare
93baf39
to
35c3435
Compare
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.
LGTM, although it is hard to review refactored changes. GitHub does not show where the changes were move, I only see addictions and subtractions
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.
Pull Request Overview
This PR refactors shared utilities into dedicated modules to break cyclic dependencies in the e2e tests suite. Key changes include:
- Extracting the
Phase
enum,in_desired_state
, andwait_for
logic intophase.py
,mongodb_utils_state.py
, andmongodb_common.py
. - Introducing
MultiClusterClient
in its own module for cross-cluster API calls. - Cleaning up imports across test files and core
kubetester
modules and removing re-exports that caused cycles.
Reviewed Changes
Copilot reviewed 238 out of 238 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
docker/mongodb-kubernetes-tests/kubetester/phase.py | New module defining the Phase enum |
docker/mongodb-kubernetes-tests/kubetester/mongodb_utils_state.py | New helper for state checks (in_desired_state ) |
docker/mongodb-kubernetes-tests/kubetester/mongodb_common.py | New module for common MongoDB operations |
docker/mongodb-kubernetes-tests/kubetester/multicluster_client.py | New MultiClusterClient class |
docker/mongodb-kubernetes-tests/kubetester/opsmanager.py | Updated imports to use new modules |
docker/mongodb-kubernetes-tests/kubetester/init.py | Removed re-exports to prevent cyclic imports |
Comments suppressed due to low confidence (2)
docker/mongodb-kubernetes-tests/kubetester/init.py:12
- Removing the re-export of
MongoDB
from the package root could break consumers relying onfrom kubetester import MongoDB
. If backward compatibility is required, consider re-adding it or providing a deprecation path.
from .mongodb import MongoDB
docker/mongodb-kubernetes-tests/kubetester/opsmanager.py:229
- The return type annotation
CustomObject
is not imported or defined in this module. If this method always returns aMongoDB
, change the annotation toMongoDB
and import it at the top.
def get_appdb_resource(self) -> CustomObject:
TRACER.start_as_current_span("wait_for") | ||
|
||
def wait_for(self, fn, timeout=None, should_raise=True): | ||
if timeout is None: | ||
timeout = 600 | ||
initial_timeout = timeout | ||
|
||
wait = 3 | ||
while timeout > 0: | ||
try: | ||
self.reload() | ||
except Exception as e: | ||
print(f"Caught error: {e} while waiting for {fn.__name__}") | ||
pass | ||
if fn(self): | ||
return True | ||
timeout -= wait | ||
time.sleep(wait) | ||
|
||
if should_raise: | ||
raise Exception("Timeout ({}) reached while waiting for {}".format(initial_timeout, self)) |
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.
Invoking start_as_current_span
at class definition time has no effect on the wait_for
method. Consider using it as a decorator on wait_for
or moving it inside the method body with a with
statement.
TRACER.start_as_current_span("wait_for") | |
def wait_for(self, fn, timeout=None, should_raise=True): | |
if timeout is None: | |
timeout = 600 | |
initial_timeout = timeout | |
wait = 3 | |
while timeout > 0: | |
try: | |
self.reload() | |
except Exception as e: | |
print(f"Caught error: {e} while waiting for {fn.__name__}") | |
pass | |
if fn(self): | |
return True | |
timeout -= wait | |
time.sleep(wait) | |
if should_raise: | |
raise Exception("Timeout ({}) reached while waiting for {}".format(initial_timeout, self)) | |
def wait_for(self, fn, timeout=None, should_raise=True): | |
with TRACER.start_as_current_span("wait_for"): | |
if timeout is None: | |
timeout = 600 | |
initial_timeout = timeout | |
wait = 3 | |
while timeout > 0: | |
try: | |
self.reload() | |
except Exception as e: | |
print(f"Caught error: {e} while waiting for {fn.__name__}") | |
pass | |
if fn(self): | |
return True | |
timeout -= wait | |
time.sleep(wait) | |
if should_raise: | |
raise Exception("Timeout ({}) reached while waiting for {}".format(initial_timeout, self)) |
Copilot uses AI. Check for mistakes.
|
||
is_in_desired_state = current_state == desired_state | ||
if msg_regexp is not None: | ||
print("msg_regexp: " + str(msg_regexp)) |
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.
This print
appears to be residual debug output. Consider replacing it with a proper logger.debug
call or removing it.
print("msg_regexp: " + str(msg_regexp)) | |
TRACER.get_current_span().add_event("Debug: msg_regexp value", {"msg_regexp": str(msg_regexp)}) |
Copilot uses AI. Check for mistakes.
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.
It's nice to clean up some of this mess 🙏
Summary
This PR contains no functional changes - only moving functions around.
It's extracting common bits imported from different places to their own files which resolves some cyclic dependencies in the code.
It's by no means a complete refactor, it's an extracted refactor from the followup change (#173) which triggered cyclic dependencies in the first place.
Proof of Work
Green EVG
Checklist
Reminder (Please remove this when merging)