Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/unit/gapic/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep):
)


@pytest.mark.skip(reason="Known flaky due to floating point comparison. #866")
def test_wrap_method_with_overriding_timeout_as_a_number():
method = mock.Mock(spec=["__call__"], return_value=42)
default_retry = retry.Retry()
Expand All @@ -200,6 +201,8 @@ def test_wrap_method_with_overriding_timeout_as_a_number():
method, default_retry, default_timeout
)

# Using "result = wrapped_method(timeout=22)" fails since wrapped_method
# does floating point calculations that results in 21.987.. instead of 22
result = wrapped_method(timeout=22)

assert result == 42
Expand All @@ -210,6 +213,24 @@ def test_wrap_method_with_overriding_timeout_as_a_number():
assert actual_timeout == pytest.approx(22, abs=0.01)


def test_wrap_method_with_overriding_constant_timeout():
method = mock.Mock(spec=["__call__"], return_value=42)
default_retry = retry.Retry()
default_timeout = timeout.ConstantTimeout(60)
wrapped_method = google.api_core.gapic_v1.method.wrap_method(
method, default_retry, default_timeout
)

result = wrapped_method(timeout=timeout.ConstantTimeout(22))

assert result == 42

actual_timeout = method.call_args[1]["timeout"]
metadata = method.call_args[1]["metadata"]
assert metadata == mock.ANY
assert actual_timeout == 22


def test_wrap_method_with_call():
method = mock.Mock()
mock_call = mock.Mock()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/gapic/test_routing_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def test__urlencode_param(key, value, expected):
def test__urlencode_param_caching_performance():
import time

key = "key" * 100
value = "value" * 100
key = "key" * 10000
value = "value" * 10000
# time with empty cache
start_time = time.perf_counter()
routing_header._urlencode_param(key, value)
Expand Down
Loading