Skip to content

Commit 9340408

Browse files
authored
fix: flaky tests due to imprecision in floating point calculation and performance test setup (#865)
Fix flaky tests due to imprecision in floating point calculation and performance test setup
1 parent c969186 commit 9340408

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

tests/unit/gapic/test_method.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep):
192192
)
193193

194194

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

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

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

212215

216+
def test_wrap_method_with_overriding_constant_timeout():
217+
method = mock.Mock(spec=["__call__"], return_value=42)
218+
default_retry = retry.Retry()
219+
default_timeout = timeout.ConstantTimeout(60)
220+
wrapped_method = google.api_core.gapic_v1.method.wrap_method(
221+
method, default_retry, default_timeout
222+
)
223+
224+
result = wrapped_method(timeout=timeout.ConstantTimeout(22))
225+
226+
assert result == 42
227+
228+
actual_timeout = method.call_args[1]["timeout"]
229+
metadata = method.call_args[1]["metadata"]
230+
assert metadata == mock.ANY
231+
assert actual_timeout == 22
232+
233+
213234
def test_wrap_method_with_call():
214235
method = mock.Mock()
215236
mock_call = mock.Mock()

tests/unit/gapic/test_routing_header.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def test__urlencode_param(key, value, expected):
9090
def test__urlencode_param_caching_performance():
9191
import time
9292

93-
key = "key" * 100
94-
value = "value" * 100
93+
key = "key" * 10000
94+
value = "value" * 10000
9595
# time with empty cache
9696
start_time = time.perf_counter()
9797
routing_header._urlencode_param(key, value)

0 commit comments

Comments
 (0)