Esempio n. 1
0
def test_record_different_groups(clear_cache):
    request = helloworld_pb2.HelloRequest()
    context = FakeServicerContext()
    with freeze_time(datetime.utcfromtimestamp(14)):
        count, time_left = record_call(FakeGRPCServer.Foo,
                                       request,
                                       context,
                                       time_period=10)

    assert count == 1
    assert time_left == 6

    with freeze_time(datetime.utcfromtimestamp(16)):
        count, time_left = record_call(FakeGRPCServer.Bar,
                                       request,
                                       context,
                                       time_period=10)

    assert count == 1
    assert time_left == 4
Esempio n. 2
0
def test_record_same_group_but_different_keys(clear_cache):
    request = helloworld_pb2.HelloRequest()
    context = FakeServicerContext()
    with freeze_time(datetime.utcfromtimestamp(14)):
        count, time_left = record_call(FakeGRPCServer.Foo,
                                       request,
                                       context,
                                       time_period=10)

    assert count == 1
    assert time_left == 6

    with freeze_time(datetime.utcfromtimestamp(16)):
        count, time_left = record_call(
            FakeGRPCServer.Bar,
            helloworld_pb2.HelloRequest(name="Aleksandr"),
            context,
            time_period=10,
            group="FakeGRPCServer.Foo",
            keys=["request:name"],
        )

    assert count == 1
    assert time_left == 4