Ejemplo n.º 1
0
def test_lease_keep_alive_empty_wallet():
    # There should be no calls to RetainLease if the wallet is empty
    lease_wallet = LeaseWallet()
    lease_client = MockLeaseClient(lease_wallet)
    max_loops = MaxKeepAliveLoops(3)
    keep_alive = LeaseKeepAlive(lease_client, resource='A', rpc_interval_seconds=.1,
                                keep_running_cb=max_loops)
    keep_alive.wait_until_done()
    assert 3 == max_loops.cur_loops
    assert 0 == lease_client.retain_lease_calls
Ejemplo n.º 2
0
def test_lease_keep_alive_filled_wallet():
    # Ensure that there are expected retain_lease calls when
    # the LeaseWallet has a resource.
    lease_wallet = LeaseWallet()
    lease_A = _create_lease('A', 'epoch', [1])
    lease_wallet.add(lease_A)
    lease_client = MockLeaseClient(lease_wallet)
    max_loops = MaxKeepAliveLoops(3)
    keep_alive = LeaseKeepAlive(lease_client, resource='A', rpc_interval_seconds=.1,
                                keep_running_cb=max_loops)
    keep_alive.wait_until_done()
    assert 3 == max_loops.cur_loops
    assert 3 == lease_client.retain_lease_calls
    assert None != lease_wallet.get_lease('A')
Ejemplo n.º 3
0
def test_lease_keep_alive_lease_use_result_error():
    # Ensure that an exception thrown when calling retain_lease
    # will not take down the loop.
    lease_wallet = LeaseWallet()
    lease_A = _create_lease('A', 'epoch', [1])
    lease_wallet.add(lease_A)
    lease_client = MockLeaseClient(lease_wallet, error_on_call_N=6)
    max_loops = MaxKeepAliveLoops(10)
    keep_alive = LeaseKeepAlive(lease_client,
                                resource='A',
                                rpc_interval_seconds=.1,
                                keep_running_cb=max_loops)
    keep_alive.wait_until_done()
    assert 10 == max_loops.cur_loops
    assert 6 == lease_client.retain_lease_calls
    assert None == lease_wallet.get_lease('A')
Ejemplo n.º 4
0
def test_lease_keep_alive_lease_use_result_error():
    # Ensure that an exception thrown when calling retain_lease
    # will not take down the loop.
    lease_wallet = LeaseWallet()
    lease_A = _create_lease('A', 'epoch', [1])
    lease_wallet.add(lease_A)
    lease_client = MockLeaseClient(lease_wallet, error_on_call_N=6)
    max_loops = MaxKeepAliveLoops(10)
    keep_alive = LeaseKeepAlive(lease_client, resource='A', rpc_interval_seconds=.1,
                                keep_running_cb=max_loops)
    keep_alive.wait_until_done()
    assert 10 == max_loops.cur_loops
    assert 6 == lease_client.retain_lease_calls
    with pytest.raises(NoSuchLease) as excinfo:
        lease_wallet.get_lease('A')
    # The exception should be clear when translated to text.
    assert 'No lease for resource "A"' == str(excinfo.value)