Skip to content

Commit

Permalink
Do not assert number of threads but thread names
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen committed May 30, 2024
1 parent 106b313 commit 4e0fb86
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion spine_engine/server/engine_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def close(self):
"""Closes the server by sending a KILL message to this thread using a PAIR socket."""
if self.auth is not None:
self.auth.stop()
time.sleep(0.2) # wait a bit until authenticator has been closed
while self.auth.is_alive():
pass

Check warning on line 87 in spine_engine/server/engine_server.py

View check run for this annotation

Codecov / codecov/patch

spine_engine/server/engine_server.py#L87

Added line #L87 was not covered by tests
self.ctrl_msg_sender.send(b"KILL")
self.join() # Wait for the thread to finish and sockets to close
self.ctrl_msg_sender.close() # Close this in the same thread that it was created in
Expand Down
5 changes: 1 addition & 4 deletions tests/project_item/test_ExecutableItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Unit tests for ExecutableItem.
"""
""" Unit tests for ExecutableItem. """
from tempfile import TemporaryDirectory
import unittest
from unittest import mock
Expand Down
6 changes: 2 additions & 4 deletions tests/server/test_EngineServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Unit tests for EngineServer class.
"""
""" Unit tests for EngineServer class. """

import threading
import unittest
Expand Down Expand Up @@ -175,7 +173,7 @@ def test_engineserver_close(self):
self.assertTrue(server.ctrl_msg_sender.closed) # PAIR socket should be closed
self.assertTrue(server._context.closed) # Context should be closed
self.assertFalse(server.is_alive()) # server thread should not be alive
self.assertEqual(threading.active_count(), 1) # Only one thread running after close
self.assertTrue(all(thread.name != "EngineServerThread" for thread in threading.enumerate()))


if __name__ == "__main__":
Expand Down

0 comments on commit 4e0fb86

Please sign in to comment.