Skip to content

Commit

Permalink
Added Unit tests for Shutdown/restart logic
Browse files Browse the repository at this point in the history
(LNDENG-740)
  • Loading branch information
mcw-work committed Nov 21, 2023
1 parent 32ba71e commit 2b9c0a3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions landscape/client/manager/tests/test_shutdownmanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from unittest.mock import patch
from twisted.internet import task

from landscape.client.manager.shutdownmanager import ShutdownManager
from landscape.client.tests.helpers import LandscapeTest
from landscape.client.tests.helpers import ManagerHelper


class ShutdownManagerTest(LandscapeTest):

helpers = [ManagerHelper]

def setUp(self):
super().setUp()

self.broker_service.message_store.set_accepted_types(
["shutdown", "operation-result"],
)
self.broker_service.pinger.start()

self.clock = task.Clock()
self.plugin = ShutdownManager()
self.plugin.reactor = self.clock

self.manager.add(self.plugin)

def tearDown(self):
return super().tearDown()

@patch('landscape.client.manager.shutdownmanager.ShutdownManager._Reboot')
def test_reboot(self, mock_reboot):
message = {"type": "shutdown", "reboot": True, "operation-id": 100}
deferred = self.plugin._handle_shutdown(message)

mock_reboot.assert_called_once()
return deferred

@patch('landscape.client.manager.shutdownmanager.reactor')
def test_shutdown(self, mock_reactor):

message = {"type": "shutdown", "reboot": False, "operation-id": 101}
self.plugin._handle_shutdown(message)

mock_reactor.callLater.assert_called_once()

# check it was the shutdown method requested
arg = mock_reactor.callLater.call_args.args[1]
name = getattr(arg, "__name__", str(arg))
self.assertEqual(name, "_Shutdown")

0 comments on commit 2b9c0a3

Please sign in to comment.