async def test_check_service_status(v1, v2, status):
    svc = Service()
    s1 = ServiceStatus()
    s2 = ServiceStatus()
    health = Health({svc: [s1, s2]})
    async with ChannelFor([svc, health]) as channel:
        stub = HealthStub(channel)
        s1.set(v1)
        s2.set(v2)
        response = await stub.Check(HealthCheckRequest(service=SERVICE_NAME))
        assert response == HealthCheckResponse(status=status)
Esempio n. 2
0
async def test_check_service_status(loop, v1, v2, status):
    svc = Service()
    s1 = ServiceStatus(loop=loop)
    s2 = ServiceStatus(loop=loop)
    health = Health({svc: [s1, s2]})
    with channel_for([svc, health], loop=loop) as channel:
        stub = HealthStub(channel)
        s1.set(v1)
        s2.set(v2)
        response = await stub.Check(
            HealthCheckRequest(service=Service.__name__, ))
        assert response == HealthCheckResponse(status=status)
Esempio n. 3
0
async def test_watch_service_status(loop):
    svc = Service()
    s1 = ServiceStatus(loop=loop)
    s2 = ServiceStatus(loop=loop)
    health = Health({svc: [s1, s2]})
    with channel_for([svc, health], loop=loop) as channel:
        stub = HealthStub(channel)
        async with stub.Watch.open() as stream:
            await stream.send_message(
                HealthCheckRequest(service=Service.__name__, ))
            assert await stream.recv_message() == HealthCheckResponse(
                status=HealthCheckResponse.UNKNOWN, )
            s1.set(True)
            assert await stream.recv_message() == HealthCheckResponse(
                status=HealthCheckResponse.NOT_SERVING, )
            s2.set(True)
            assert await stream.recv_message() == HealthCheckResponse(
                status=HealthCheckResponse.SERVING, )
            s1.set(False)
            assert await stream.recv_message() == HealthCheckResponse(
                status=HealthCheckResponse.NOT_SERVING, )
            s1.set(True)
            assert await stream.recv_message() == HealthCheckResponse(
                status=HealthCheckResponse.SERVING, )

            # check that there are no unnecessary messages if status isn't
            # changed
            s1.set(True)
            try:
                with async_timeout.timeout(0.01):
                    assert not await stream.recv_message()
            except asyncio.TimeoutError:
                pass

            await stream.cancel()