示例#1
0
def test_one_host():
    host1 = 'host1'
    slave1 = Slave(host1, 'slave1')
    slave2 = Slave(host1, 'slave2')

    # Create a new slaves list.
    slaves = IdleSlaves()

    # Add some slaves.
    slaves.add(slave1)
    assert slaves._max_count == 1
    slaves.add(slave2)
    assert slaves._max_count == 2

    # Remove some slaves.
    slaves.remove(slave1)
    assert slaves._max_count == 1
    with pytest.raises(KeyError):
        slaves.remove(slave1)
    assert slaves._max_count == 1
    slaves._consistency_check()
    slaves.remove(slave2)
    assert slaves._max_count == 0
    slaves._consistency_check()

    with pytest.raises(KeyError):
        slaves.pop()
def test_one_host():
    host1 = 'host1'
    slave1 = Slave(host1, 'slave1')
    slave2 = Slave(host1, 'slave2')

    # Create a new slaves list.
    slaves = IdleSlaves()

    # Add some slaves.
    slaves.add(slave1)
    assert slaves._max_count == 1
    slaves.add(slave2)
    assert slaves._max_count == 2

    # Remove some slaves.
    slaves.remove(slave1)
    assert slaves._max_count == 1
    with pytest.raises(KeyError):
        slaves.remove(slave1)
    assert slaves._max_count == 1
    slaves._consistency_check()
    slaves.remove(slave2)
    assert slaves._max_count == 0
    slaves._consistency_check()

    with pytest.raises(KeyError):
        slaves.pop()
示例#3
0
def test_two_hosts():
    host1 = 'host1'
    slave1 = Slave(host1, 'slave1')
    slave2 = Slave(host1, 'slave2')

    host2 = 'host2'
    slave3 = Slave(host2, 'slave3')
    slave4 = Slave(host2, 'slave4')
    slave5 = Slave(host2, 'slave5')

    # Create a new slaves list.
    slaves = IdleSlaves()

    # Add some slaves.
    slaves.add(slave1)
    assert slaves._max_count == 1
    slaves._consistency_check()
    slaves.add(slave2)
    assert slaves._max_count == 2
    slaves._consistency_check()
    slaves.add(slave3)
    assert slaves._max_count == 2
    slaves._consistency_check()
    slaves.add(slave4)
    assert slaves._max_count == 2
    slaves._consistency_check()
    slaves.add(slave5)
    assert slaves._max_count == 3
    slaves._consistency_check()

    # Pop a slave.
    popped_slave = slaves.pop()
    assert popped_slave.host == host2
    assert slaves._max_count == 2
    slaves._consistency_check()

    # Make sure that additional slaves are popped for alternating hosts.
    popped2 = slaves.pop()
    assert slaves._max_count == 2
    slaves._consistency_check()
    popped3 = slaves.pop()
    assert slaves._max_count == 1
    assert popped2.host != popped3.host
    slaves._consistency_check()
def test_two_hosts():
    host1 = 'host1'
    slave1 = Slave(host1, 'slave1')
    slave2 = Slave(host1, 'slave2')

    host2 = 'host2'
    slave3 = Slave(host2, 'slave3')
    slave4 = Slave(host2, 'slave4')
    slave5 = Slave(host2, 'slave5')

    # Create a new slaves list.
    slaves = IdleSlaves()

    # Add some slaves.
    slaves.add(slave1)
    assert slaves._max_count == 1
    slaves._consistency_check()
    slaves.add(slave2)
    assert slaves._max_count == 2
    slaves._consistency_check()
    slaves.add(slave3)
    assert slaves._max_count == 2
    slaves._consistency_check()
    slaves.add(slave4)
    assert slaves._max_count == 2
    slaves._consistency_check()
    slaves.add(slave5)
    assert slaves._max_count == 3
    slaves._consistency_check()

    # Pop a slave.
    popped_slave = slaves.pop()
    assert popped_slave.host == host2
    assert slaves._max_count == 2
    slaves._consistency_check()

    # Make sure that additional slaves are popped for alternating hosts.
    popped2 = slaves.pop()
    assert slaves._max_count == 2
    slaves._consistency_check()
    popped3 = slaves.pop()
    assert slaves._max_count == 1
    assert popped2.host != popped3.host
    slaves._consistency_check()