Skip to content

Commit

Permalink
Speed up dlg daemon unit tests
Browse files Browse the repository at this point in the history
The unit tests for the dlg daemon check at various times that the
underlying nm/dim/mm processes the daemon starts or stops have actually
been started or stopped by checking if the manager REST port is open.
They did this using our utils.portIsOpen/Closed functions together with
a timeout.

How these functions work is a bit special: they don't give up on their
mission until the condition has been met or the timeout has expired, and
therefore they should be used with caution. For example, portIsOpen will
return False only after trying to connect to the given host/port
until the timeout expires, and True if within that timeout it succeeds
in connecting. As such, it's better suited for checking if a service has
become offline, but not really for checking if a service is down, as the
full timeout would have to be waited for to make that assessment.

This was the situation in which some unit tests were on: they waited for
long times to check a condition that would be checked much faster if you
turned the tables. In the case above, instead of waiting for False to be
returned from portIsOpen, a faster alternative is to wait for True to be
returned from portIsClosed. This commit changes these checks in a couple
of places, bringing the total runtime of the test_daemon unit tests by
about 30 seconds (from ~140 to ~110 seconds in my laptop).

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Jun 2, 2022
1 parent 7867702 commit 4055177
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions daliuge-engine/test/manager/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def test_mm_starts(self):
def test_nothing_starts(self):
# Nothing should start now
self.create_daemon(master=False, noNM=True, disable_zeroconf=True)
self.assertFalse(
utils.portIsOpen("localhost", constants.NODE_DEFAULT_REST_PORT, 0),
self.assertTrue(
utils.portIsClosed("localhost", constants.NODE_DEFAULT_REST_PORT, 0),
"NM started but it should not have",
)
self.assertFalse(
utils.portIsOpen("localhost", constants.MASTER_DEFAULT_REST_PORT, 0),
self.assertTrue(
utils.portIsClosed("localhost", constants.MASTER_DEFAULT_REST_PORT, 0),
"NM started but it should not have",
)

Expand Down Expand Up @@ -297,8 +297,8 @@ def test_stop_dataisland_via_rest(self):

# Check that the DataIsland stopped
self._stop("island", http.HTTPStatus.OK, "")
self.assertFalse(
utils.portIsOpen("localhost", constants.ISLAND_DEFAULT_REST_PORT, _TIMEOUT),
self.assertTrue(
utils.portIsClosed("localhost", constants.ISLAND_DEFAULT_REST_PORT, _TIMEOUT),
"The DIM did not stop successfully",
)

Expand All @@ -321,14 +321,15 @@ def test_stop_start_node_via_rest(self):

# Check that the NM stops
self._stop("node", http.HTTPStatus.OK, "")
self.assertFalse(
utils.portIsOpen("localhost", constants.NODE_DEFAULT_REST_PORT, _TIMEOUT),
self.assertTrue(
utils.portIsClosed('localhost', constants.NODE_DEFAULT_REST_PORT, _TIMEOUT),
"The node did not stop successfully",
)

# Check that the NM starts
self._start("node", http.HTTPStatus.OK, {"pid": nodes})
self.assertTrue(
utils.portIsOpen("localhost", constants.NODE_DEFAULT_REST_PORT, _TIMEOUT),
utils.portIsOpen('localhost', constants.NODE_DEFAULT_REST_PORT, _TIMEOUT),
"The node did not start successfully",
)

Expand All @@ -345,8 +346,8 @@ def test_start_stop_master_via_rest(self):

# Check that the MM stops
self._stop("master", http.HTTPStatus.OK, "")
self.assertFalse(
utils.portIsOpen("localhost", constants.MASTER_DEFAULT_REST_PORT, _TIMEOUT),
self.assertTrue(
utils.portIsClosed("localhost", constants.MASTER_DEFAULT_REST_PORT, _TIMEOUT),
"The MM did not stop successfully",
)

Expand Down

0 comments on commit 4055177

Please sign in to comment.