コード例 #1
0
def test_pool3(client):
    """
    Tests that when getting docker hosts, hosts with half-open circuits are returned
    """

    with client.application.app_context():
        pool = DockerPool(([None, ["localhost:1234"], 2], ))
        executor = Executor(client.application, pool)
        executor.get_circuit("localhost:1234").half_open()

        host, port, client = pool.get_client(executor, "test-123")
        expect(host).to_equal("localhost")
        expect(port).to_equal(1234)
コード例 #2
0
def test_pool2(client):
    """
    Tests that when getting docker hosts, hosts in the blacklist are not returned
    """

    with client.application.app_context():
        pool = DockerPool(([None, ["localhost:1234", "localhost:4567"], 2], ))
        executor = Executor(client.application, pool)

        host, port, client = pool.get_client(executor,
                                             "test-123",
                                             blacklist=set(["localhost:4567"]))
        expect(host).to_equal("localhost")
        expect(port).to_equal(1234)
コード例 #3
0
def test_pool6(client):
    """
    Tests getting client when no farms match raises
    """

    with client.application.app_context():
        pool = DockerPool(
            ([re.compile(r"test-.+"), ["localhost:1234", "localhost:4567"],
              2], ))
        executor = Executor(client.application, pool=pool)

        message = "Failed to find a docker host for task id qwe-123."
        with expect.error_to_happen(NoAvailableHostsError, message=message):
            pool.get_client(executor, "qwe-123")
コード例 #4
0
def test_circuit6(client):
    """
    Tests that when marking a container as done with a
    docker host that's not accessible, the circuit is open and
    a HostUnavailableError is raised
    """

    with client.application.app_context():
        client.application.config["DOCKER_CIRCUIT_BREAKER_MAX_FAILS"] = 1

        task, job, execution = JobExecutionFixture.new_defaults(
            docker_host="localhost",
            docker_port=4567,
            container_id=str(uuid4()))
        pool = DockerPool(([None, ["localhost:4567"], 2], ))
        executor = Executor(client.application, pool)

        expect(executor.get_circuit("localhost:4567").current_state).to_equal(
            "closed")

        with expect.error_to_happen(HostUnavailableError):
            executor.mark_as_done(task, job, execution)

        expect(executor.get_circuit("localhost:4567").current_state).to_equal(
            "open")
コード例 #5
0
def test_circuit1(client):
    """
    Tests that when updating with a docker host that's not accessible,
    the circuit is open and a HostUnavailableError is raised
    """

    with client.application.app_context():
        client.application.config["DOCKER_CIRCUIT_BREAKER_MAX_FAILS"] = 2

        task, job, execution = JobExecutionFixture.new_defaults(
            docker_host="localhost", docker_port=4567)
        pool = DockerPool(([None, ["localhost:4567"], 2], ))
        executor = Executor(client.application, pool)

        expect(executor.get_circuit("localhost:4567").current_state).to_equal(
            "closed")

        with expect.error_to_happen(HostUnavailableError):
            executor.update_image(task, job, execution, "ubuntu", "latest")

        expect(executor.get_circuit("localhost:4567").current_state).to_equal(
            "open")