Skip to content

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

Merged
merged 3 commits into from
Jun 4, 2025
Merged

Conversation

lsierant
Copy link
Contributor

@lsierant lsierant commented Jun 3, 2025

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

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you checked for release_note changes?

Reminder (Please remove this when merging)

  • Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible
  • Our Short Guide for PRs: Link
  • Remember the following Communication Standards - use comment prefixes for clarity:
    • blocking: Must be addressed before approval.
    • follow-up: Can be addressed in a later PR or ticket.
    • q: Clarifying question.
    • nit: Non-blocking suggestions.
    • note: Side-note, non-actionable. Example: Praise
    • --> no prefix is considered a question

@lsierant lsierant force-pushed the lsierant/pytest-refactor branch from 043f6e7 to 93baf39 Compare June 3, 2025 11:29
@lsierant lsierant force-pushed the lsierant/pytest-refactor branch from 93baf39 to 35c3435 Compare June 4, 2025 06:38
@lsierant lsierant marked this pull request as ready for review June 4, 2025 08:52
@lsierant lsierant requested a review from a team as a code owner June 4, 2025 08:52
Copy link
Collaborator

@MaciejKaras MaciejKaras left a 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

@anandsyncs anandsyncs requested a review from Copilot June 4, 2025 10:49
Copy link

@Copilot Copilot AI left a 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, and wait_for logic into phase.py, mongodb_utils_state.py, and mongodb_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 on from 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 a MongoDB, change the annotation to MongoDB and import it at the top.
def get_appdb_resource(self) -> CustomObject:

Comment on lines 13 to 33
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))
Copy link
Preview

Copilot AI Jun 4, 2025

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.

Suggested change
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))
Copy link
Preview

Copilot AI Jun 4, 2025

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.

Suggested change
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.

Copy link
Collaborator

@Julien-Ben Julien-Ben left a 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 🙏

@lsierant lsierant merged commit f29ac63 into master Jun 4, 2025
35 checks passed
@lsierant lsierant deleted the lsierant/pytest-refactor branch June 4, 2025 18:05
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.

4 participants