Ejemplo n.º 1
0
def test_get_block_numbers_timeout(mock_trigger_service):
    clear_all_items()
    set_state(url1, block_number=10, leader=True)
    set_state(url2, block_number=5, leader=False)
    with aioresponses() as responses:
        responses.post(url1, payload={'result': hex(15)})
        responses.post(url2, exception=asyncio.TimeoutError())

        get_block_numbers(event={}, context={})

    expect(url1, healthy=True, block_number=15)
    expect(url2, healthy=False, block_number=5)

    assert mock_trigger_service.called
Ejemplo n.º 2
0
def test_get_block_numbers_recover(mock_trigger_service):
    clear_all_items()
    set_state(url1, block_number=10, leader=True)
    set_state(url2, block_number=5, leader=False, is_healthy=False)
    with aioresponses() as responses:
        responses.post(url1, payload={'result': hex(15)})
        responses.post(url2, payload={'result': hex(15)})

        get_block_numbers(event={}, context={})

    expect(url1, healthy=True, block_number=15)
    expect(url2, healthy=True, block_number=15)

    assert mock_trigger_service.called
Ejemplo n.º 3
0
def test_get_block_numbers_decodes_various_content_types(mock_trigger_service):
    clear_all_items()
    set_state(url1, block_number=10, leader=True)
    set_state(url2, block_number=5, leader=False, is_healthy=False)
    with aioresponses() as responses:
        responses.post(url1,
                       payload={'result': hex(15)},
                       headers={'content-type': 'application/json'})
        responses.post(url2,
                       payload={'result': hex(15)},
                       headers={'content-type': 'text/plain'})

        get_block_numbers(event={}, context={})

    expect(url1, healthy=True, block_number=15)
    expect(url2, healthy=True, block_number=15)

    assert mock_trigger_service.called
Ejemplo n.º 4
0
def test_get_block_doesnt_update_when_no_need(mock_trigger_service,
                                              mock_cloudwatch):
    clear_all_items()
    set_state(url1, block_number=25, leader=False)
    set_state(url2, block_number=25, leader=False)
    with aioresponses() as responses:
        responses.post(url1, payload={'result': hex(25)})
        responses.post(url2, payload={'result': hex(25)})

        get_block_numbers(event={}, context={})

    expect(url1, healthy=True, block_number=25)
    expect(url2, healthy=True, block_number=25)

    assert not mock_trigger_service.called

    assert mock_cloudwatch.return_value.put_metric_data.called
    assert mock_cloudwatch.return_value.put_metric_data.call_args == mock.call(
        MetricData=[{
            'MetricName':
            'BESU node block number',
            'Timestamp':
            mock.ANY,
            'Value':
            25,
            'Unit':
            'None',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Node URL',
                'Value': 'http://url2'
            }]
        }, {
            'MetricName':
            'BESU node block number',
            'Timestamp':
            mock.ANY,
            'Value':
            25,
            'Unit':
            'None',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Node URL',
                'Value': 'http://url1'
            }]
        }, {
            'MetricName':
            'eth_getBlockNumber response time',
            'Timestamp':
            mock.ANY,
            'Value':
            mock.ANY,
            'Unit':
            'Microseconds',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Node URL',
                'Value': 'http://url2'
            }]
        }, {
            'MetricName':
            'eth_getBlockNumber response time',
            'Timestamp':
            mock.ANY,
            'Value':
            mock.ANY,
            'Unit':
            'Microseconds',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Node URL',
                'Value': 'http://url1'
            }]
        }, {
            'MetricName':
            'Number of healthy BESU nodes',
            'Timestamp':
            mock.ANY,
            'Value':
            2,
            'Unit':
            'None',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Stack name',
                'Value': 'jsonrpc-proxy-dev'
            }]
        }, {
            'MetricName':
            'BESU node block difference',
            'Timestamp':
            mock.ANY,
            'Value':
            0,
            'Unit':
            'None',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Node URL',
                'Value': 'http://url2'
            }]
        }, {
            'MetricName':
            'BESU node block difference',
            'Timestamp':
            mock.ANY,
            'Value':
            0,
            'Unit':
            'None',
            'StorageResolution':
            60,
            'Dimensions': [{
                'Name': 'Node URL',
                'Value': 'http://url1'
            }]
        }],
        Namespace='test')