From aff822c5340c02c3836633e2bb9817d200d12197 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Tue, 9 Oct 2018 17:18:21 +0200 Subject: [PATCH] correct some check, and improve signal action --- pymanager/manager.py | 6 +++++- tests/test_client_manager.py | 13 ++++++------- tests/test_manager.py | 1 - 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pymanager/manager.py b/pymanager/manager.py index 29fecb8..5b0c3cf 100755 --- a/pymanager/manager.py +++ b/pymanager/manager.py @@ -1425,8 +1425,12 @@ class Manager(): pass if self.serverHttp: logging.info("send signal to server http") - self.serverHttp.terminate() + try: + self.serverHttp.terminate() + except AttributeError: + pass logging.info("Finalize signal (%d)" % (signum)) + os._exit(0) def wait_children_commands(self): for child in self.threadCommand: diff --git a/tests/test_client_manager.py b/tests/test_client_manager.py index 6526101..768e88a 100644 --- a/tests/test_client_manager.py +++ b/tests/test_client_manager.py @@ -96,18 +96,17 @@ class TestManager(unittest.TestCase): time.sleep(1) signal.alarm(10) msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False) - assert msgjson == {'state' : 'stopped'} + self.assertEqual(msgjson['state'], 'stopped') msgjson = client.send_json({'name': 'command:test'}, 'POST', "/START", show_result=False) - assert msgjson == {'state' : 'started'} + self.assertEqual(msgjson['state'], 'started') msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False) - assert msgjson == {'state' : 'started'} + self.assertEqual(msgjson['state'], 'started') msgjson = client.send_json({'name': 'command:test', 'action': 'test'}, 'POST', "/STDIN", show_result=False) - print(msgjson) - assert msgjson == {'state' : 'ok'} + self.assertEqual(msgjson['state'], 'ok') msgjson = client.send_json({'name': 'command:test'}, 'POST', "/STOP", show_result=False) - assert msgjson == {'state' : 'stopped'} + self.assertEqual(msgjson['state'], 'stopped') msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False) - assert msgjson == {'state' : 'stopped'} + self.assertEqual(msgjson['state'], 'stopped') manage.receive_signal(15, 1) manage.wait_children_commands() diff --git a/tests/test_manager.py b/tests/test_manager.py index a3bec81..3bf0cd5 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1264,7 +1264,6 @@ class TestManager(unittest.TestCase): manage.rfile.define_return( '{"name": "test", "first-line" : "1"}' ) manage.headers = {'content-length' : '1000', 'content-type' : 'application/json'} manage._command_log() - print(manage.wfile.message) self.assertEqual(b'"empty"',manage.wfile.message) signal.alarm(0)