Пример #1
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")
Пример #2
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)
Пример #3
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")
Пример #4
0
def test_get_running4(client):
    """
    Tests getting running containers when some circuits are open
    """

    with client.application.app_context():
        match = re.compile(r"test-.+")
        client_mock = ClientFixture.new([
            ContainerFixture.new(name="fastlane-job-123",
                                 container_id="fastlane-job-123")
        ])

        pool_mock = PoolFixture.new(
            clients={
                "host:1234": ("host", 1234, client_mock),
                "host:4567": ("host", 4567, client_mock),
            },
            clients_per_regex=[(match, [("host", 1234, client_mock),
                                        ("host", 4567, client_mock)])],
            max_running={match: 2},
        )

        executor = Executor(client.application, pool_mock)

        executor.get_circuit("host:4567").open()

        result = executor.get_running_containers()

        expect(result).to_include("available")
        available = result["available"]
        expect(available).to_be_like([{
            "host": "host",
            "port": 1234,
            "available": True,
            "blacklisted": False,
            "circuit": "closed",
            "error": None,
        }])

        expect(result).to_include("unavailable")
        unavailable = result["unavailable"]

        expect(unavailable).to_be_like([{
            "host":
            "host",
            "port":
            4567,
            "available":
            False,
            "blacklisted":
            False,
            "circuit":
            "open",
            "error":
            "Timeout not elapsed yet, circuit breaker still open",
        }])

        expect(result).to_include("running")
        running = result["running"]
        expect(running).to_length(1)
        host, port, container_id = running[0]
        expect(host).to_equal("host")
        expect(port).to_equal(1234)
        expect(container_id).to_equal("fastlane-job-123")