Example #1
0
def test_validate_request_data_missing_ml_parameter_key(
        key, client_task_definition_data):
    node = CommitteeCandidate()
    node.task_data = client_task_definition_data

    del node.task_data['ml'][key]

    with pytest.raises(ValueError):
        node.validate_request_data()
Example #2
0
def test_inform_client_of_hash_voting_results(client_task_definition_data):
    node = CommitteeCandidate()
    node.task_data = client_task_definition_data

    node.conn = MagicMock()

    node.inform_client_of_hash_allocation()

    node.conn.lpush.assert_called()
Example #3
0
def test_inform_client_of_task_id(client_task_definition_data):
    node = CommitteeCandidate()
    node.task_data = client_task_definition_data

    node.conn = MagicMock()

    node.inform_client_of_task_id()

    node.conn.lpush.assert_called()
Example #4
0
def test_set_task_id_provides_consistent_hash(client_task_definition_path,
                                              client_task_definition_data):
    with open(client_task_definition_path) as request_file:
        request_data = request_file.read()

    node = CommitteeCandidate()
    node.task_data = client_task_definition_data
    node.set_task_id(request_data)

    task_id = node.task_id

    for _ in range(10):
        node.set_task_id(request_data)
        assert task_id == node.task_id
Example #5
0
def test_disable_registration_for_client_task_only_one_task_in_queue(
        redisdb, client_task_definition_path, client_task_definition_data):
    with open(client_task_definition_path) as request_file:
        request_data = request_file.read()

    node = CommitteeCandidate()
    node.conn = redisdb
    node.task_data = client_task_definition_data
    node.set_task_id(request_data)

    redisdb.lpush(CLIENT_TASK_CHANNEL, request_data)
    node.disable_registration_for_client_task()

    assert redisdb.llen(CLIENT_TASK_CHANNEL) == 0
Example #6
0
def test_inform_client_of_task_integrated(client_task_definition_data,
                                          redisdb):
    client_address = 'test_client'

    node = CommitteeCandidate()
    node.conn = redisdb

    node.task_id = '123'

    node.task_data = client_task_definition_data
    node.task_data['client_listen_address'] = client_address
    node._client_response_listening_channel = 'test_cluster'

    node.inform_client_of_task_id()

    client = Client()
    client._client_id = client_task_definition_data['client_id']
    client.conn = redisdb
    client._client_listen_address = client_address

    client.obtain_cluster_task_id()
    assert client._task_id == '123'
    assert client._cluster_address == 'test_cluster'
Example #7
0
def test_validate_request_data_invalid_type(data):
    node = CommitteeCandidate()
    node.task_data = data

    with pytest.raises(ValueError):
        node.validate_request_data()
Example #8
0
def test_validate_request_data_simple(client_task_definition_data):
    node = CommitteeCandidate()
    node.task_data = client_task_definition_data

    node.validate_request_data()