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

DM-48197: Add additional efd connection checks to ensure tests only run where they can #288

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions python/lsst/cp/pipe/utilsEfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def __init__(self, efdInstance="usdf_efd", dieOnSearch=False, log=None):
self._databaseName = "efd"
self._databaseUrl = urljoin(f"https://{authDict['host']}", authDict["path"])

self.checkConnection()

def _getAuth(self, instanceAlias):
"""Get authorization credentials.

Expand Down Expand Up @@ -89,6 +91,23 @@ def _getAuth(self, instanceAlias):
else:
raise RuntimeError(f"Could not connect to {url}")

def checkConnection(self):
"""Check the connection to the EFD.

Raises
------
RuntimeError :
Raised if the connection check fails.
"""
# The ping command will return 204 (No Content) on success.

params = {"wait_for_leader": "5s"}

response = requests.get(f"{self._databaseUrl}/ping", params=params, auth=self._auth)
response.raise_for_status()
if response.status_code != 204:
raise RuntimeError(f"Connection check failed for {self._databaseUrl}")

def getSchemaDtype(self, topicName):
"""Get datatypes for a topic.

Expand Down
7 changes: 4 additions & 3 deletions tests/test_utilsEfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
class UtilsEfdTestCase(lsst.utils.tests.TestCase):
"""Unit test for EFD access code."""

def setUp(self):
@classmethod
def setUpClass(cls):
# Initialize a client.
try:
self.client = CpEfdClient()
cls.client = CpEfdClient()
except Exception as e:
Copy link

Choose a reason for hiding this comment

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

Is this still supposed to give up on any Exception? It appears as if it should run if you can connect to the EFD, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it can't connect to the EFD with any error it should skip the tests. I'm not sure what your question is here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My question would be: why do this at all, and not just use vcr to test the code exactly the same way, but with no dependency on the EFD at all? That way the tests always do run, and you don't have to ever worry about connections.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're interested I can point you to a working example in summit_utils, it's used in a few places there for exactly this.

Copy link

Choose a reason for hiding this comment

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

All I meant was that you are raising a RuntimeError in checkConnection but here you catch any exception from CpEfdClient.__init__. But I suppose that's fine since it is reraising and not just continuing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer that this just check for a RuntimeError?

Copy link

Choose a reason for hiding this comment

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

Eh, never mind. Maybe reconsider if/when you switch to vcr and maybe it'll just be moot.

self.client = None
cls.client = None
raise unittest.SkipTest(f"Could not initialize EFD client: {e}")

def test_monochromator(self):
Expand Down
Loading