コード例 #1
0
def test_constructor(monkeypatch):
    """Testing for constructor involves checking if all needed

    variables are declared initialized
    """

    def job_consume():
        return "Thread Consuming Job"
    monkeypatch.setattr(jobs, 'JobConsumerThread', job_consume)
    manager = Manager("test")
    assert manager._sds_sync_thread is "test"
    assert manager._message_handler_thread is None
    assert manager._job_consumer_thread == "Thread Consuming Job"
コード例 #2
0
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()
コード例 #3
0
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()
コード例 #4
0
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()