rabbit_callback_test + dissappeated during merging test added back
@@ -28,6 +28,39 @@ from poseidon.poseidonMonitor import poseidonMonitor
module_logger = Logger.logger
+def test_signal_handler():
+ class MockRabbitConnection:
+ connection_closed = False
+
+ def close(self):
+ self.connection_closed = True
+ return True
+
+ class MockMonitor(Monitor):
+ # no need to init the monitor
+ def __init__(self):
+ pass
+
+ class MockScheduele:
+ call_log = []
+
+ def __init__(self):
+ self.jobs = ['job1', 'job2', 'job3']
+
+ def cancel_job(self, job):
+ self.call_log.append(job + ' cancelled')
+ return job + ' cancelled'
+
+ mock_monitor = MockMonitor()
+ mock_monitor.schedule = MockScheduele()
+ mock_monitor.rabbit_channel_connection_local = MockRabbitConnection()
+ mock_monitor.logger = module_logger
+ # signal handler seem to simply exit and kill all the jobs no matter what we pass
+ mock_monitor.signal_handler(None, None)
+ assert ['job1 cancelled', 'job2 cancelled', 'job3 cancelled'] == mock_monitor.schedule.call_log
+ assert True == mock_monitor.rabbit_channel_connection_local.connection_closed
+
+
def test_start_vent_collector():
class requests():
@staticmethod
@@ -56,6 +89,7 @@ def test_start_vent_collector():
num_cuptures = 3
mock_monitor.start_vent_collector(dev_hash, num_cuptures)
+
def test_get_q_item():
class MockMQueue:
def get(self, block):
@@ -71,3 +105,23 @@ def test_get_q_item():
mock_monitor = MockMonitor()
mock_monitor.m_queue = MockMQueue()
assert (True, "Item") == mock_monitor.get_q_item()
+
+
+def test_rabbit_callback():
+ mock_method = lambda: None
+ mock_method.routing_key = "test_routing_key"
+
+ class MockQueue:
+ item = None
+
+ def put(self, item):
+ self.item = item
+ return True
+
+ # used for testing to verify that we put right stuff there
+ def get_item(self):
+ return self.item
+
+ mock_queue = MockQueue()
+ poseidonMonitor.rabbit_callback("Channel", mock_method, "properties", "body", mock_queue)
+ assert mock_queue.get_item() == (mock_method.routing_key, "body")
\ No newline at end of file
