def test_start(): setattr(__builtin__, "NS", maps.NamedDict()) NS.publisher_id = "node_agent" # Creating dummy job sds_job = jobs.JobConsumerThread() # Testing to start the sds_sync thread manager = Manager(sds_job) manager.start() assert manager._sds_sync_thread._complete.is_set() is False # Testing to start all threads sds_job = jobs.JobConsumerThread() message_job = jobs.JobConsumerThread() manager = Manager(sds_job, message_job) manager.start() assert manager._message_handler_thread._complete.is_set() is False # Testig with None Value manager = Manager(None) manager.start() # Testing for type of argument passed test_job = "Testing for failure" manager = Manager(test_job) with pytest.raises(AttributeError): manager.start()
def __init__( self, sds_sync_thread, message_handler_thread=None, ): self._sds_sync_thread = sds_sync_thread self._job_consumer_thread = jobs.JobConsumerThread() self._message_handler_thread = message_handler_thread
def test_stop(): setattr(__builtin__, "NS", maps.NamedDict()) NS.publisher_id = "node_agent" # Creating dummy job sds_job = jobs.JobConsumerThread() # Testing to stop the sds_sync thread manager = Manager(sds_job) manager.stop() assert manager._sds_sync_thread._complete.is_set() # Testing to stop all threads sds_job = jobs.JobConsumerThread() message_job = jobs.JobConsumerThread() manager = Manager(sds_job, message_job) manager.stop() assert manager._sds_sync_thread._complete.is_set() and \ manager._job_consumer_thread._complete.is_set() and \ manager._message_handler_thread._complete.is_set() manager = Manager(None) manager.stop()
def test_join(mock_join): mock_join.return_value = 'Done' setattr(__builtin__, "NS", maps.NamedDict()) NS.publisher_id = "node_agent" # Creating dummy job sds_job = jobs.JobConsumerThread() # Testing to start the sds_sync thread manager = Manager(sds_job) manager.start() manager.join() assert manager._sds_sync_thread._complete.is_set() is False # Testing to start all threads sds_job = jobs.JobConsumerThread() message_job = jobs.JobConsumerThread() manager = Manager(sds_job, message_job) manager.start() manager.join() # Testig with None Value manager = Manager(None) manager.start() manager.join()
def test_job_consumer_thread(load_all, sleep, thread): test_init.init() thread.return_value = MagicMock() sleep.return_value = None job = NS.tendrl.objects.Job(job_id="808a4162-4b70-4ff0-b218-45dbe371e545", status="new", payload={"status": "new"}) load_all.return_value = [job] NS.publisher_id = "testing" obj = jobs.JobConsumerThread() with patch.object(NS.node_context, "load") as nc_load: NS.node_context.fqdn = "tendrl-node-1" nc_load.return_value = NS.node_context with patch.object(NS.tendrl_context, "load") as tc_load: with patch.object(obj._complete, "is_set", is_set): NS.tendrl_context.integration_id = \ "b0b18359-3444-40b7-aa99-853f1b7308de" tc_load.return_value = NS.tendrl_context obj.run()
def test_constructor(): test_job = jobs.JobConsumerThread() assert not test_job._complete._Event__flag