Waiting for state changes

Following the deployment, we expect the deployment and services to all become active, but this does not happen instantaneously. Depending on your environment, it may happen quite quickly, or fairly slowly. The bane of integration tests is not being able to know when something has completed, and working around the issue with an invocation of sleep() to wait a little longer. In this example, we explicitly check the status rather than just waiting an arbitrary amount of time and hoping the system is ready to go:

@pytest.mark.dependency(depends=["test_deployment_ready"])def test_pods_running(kube_v1_client):    TOTAL_TIMEOUT_SECONDS = 300    DELAY_BETWEEN_REQUESTS_SECONDS = 5    now = time.time() while (time.time() < now+TOTAL_TIMEOUT_SECONDS): ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.