Skip to content

Commit a23ccf5

Browse files
committed
chore: cleanup flake in tests
1 parent 7b2b906 commit a23ccf5

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

tests/test_api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import json
2-
import time
32
import unittest
43
import uuid
5-
from concurrent.futures import thread
64
from unittest import mock
75

86
import pytest
@@ -41,9 +39,11 @@ def data(self):
4139

4240
return MockResponse(None, 200)
4341

42+
4443
class ApiClientTests(unittest.TestCase):
4544

4645
received_timeout_total = None
46+
4747
def mock_urllib3_timeout_request(method,
4848
url,
4949
body,
@@ -166,7 +166,7 @@ def test_request_config_timeout(self, mock_request):
166166
service = WriteService(local_client)
167167
with pytest.raises(ConnectTimeoutError):
168168
service.post_write("TEST_ORG", "TEST_BUCKET", "data,foo=bar val=3.14",
169-
_preload_content=False)
169+
_preload_content=False)
170170
self.assertEqual(0.3, self.received_timeout_total)
171171
self.received_timeout_total = None
172172

tests/test_influxdb_client_3.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,16 @@ def test_write_options(self):
8585
flush_interval=500,))
8686
)
8787

88-
assert isinstance(client._write_client_options["write_options"], WriteOptions)
89-
assert client._write_client_options["success_callback"]("an_arg") == True
90-
assert client._write_client_options["error_callback"]("an_arg") == False
91-
assert client._write_client_options["extra_arg"] == "ignored"
92-
assert client._write_client_options["write_options"].timeout == 30_000
93-
assert client._write_client_options["write_options"].max_retries == 0
94-
assert client._write_client_options["write_options"].max_retry_time == 0
95-
assert client._write_client_options["write_options"].max_retry_delay == 0
96-
assert client._write_client_options["write_options"].write_type == WriteType.synchronous
97-
assert client._write_client_options["write_options"].flush_interval == 500
98-
88+
self.assertIsInstance(client._write_client_options["write_options"], WriteOptions)
89+
self.assertTrue(client._write_client_options["success_callback"]("an_arg"))
90+
self.assertFalse(client._write_client_options["error_callback"]("an_arg"))
91+
self.assertEqual("ignored", client._write_client_options["extra_arg"])
92+
self.assertEqual(30_000, client._write_client_options["write_options"].timeout)
93+
self.assertEqual(0, client._write_client_options["write_options"].max_retries)
94+
self.assertEqual(0, client._write_client_options["write_options"].max_retry_time)
95+
self.assertEqual(0, client._write_client_options["write_options"].max_retry_delay)
96+
self.assertEqual(WriteType.synchronous, client._write_client_options["write_options"].write_type)
97+
self.assertEqual(500, client._write_client_options["write_options"].flush_interval)
9998

10099
def test_default_write_options(self):
101100
client = InfluxDBClient3(
@@ -105,10 +104,12 @@ def test_default_write_options(self):
105104
database="my_db",
106105
)
107106

108-
assert client._write_client_options["write_options"].write_type == DefaultWriteOptions.write_type.value
109-
assert client._write_client_options["write_options"].no_sync == DefaultWriteOptions.no_sync.value
110-
assert client._write_client_options["write_options"].write_precision == DefaultWriteOptions.write_precision.value
111-
assert client._write_client_options["write_options"].timeout == DefaultWriteOptions.timeout.value
107+
self.assertEqual(DefaultWriteOptions.write_type.value,
108+
client._write_client_options["write_options"].write_type)
109+
self.assertEqual(DefaultWriteOptions.no_sync.value, client._write_client_options["write_options"].no_sync)
110+
self.assertEqual(DefaultWriteOptions.write_precision.value,
111+
client._write_client_options["write_options"].write_precision)
112+
self.assertEqual(DefaultWriteOptions.timeout.value, client._write_client_options["write_options"].timeout)
112113

113114
@asyncio_run
114115
async def test_query_async(self):

tests/test_influxdb_client_3_integration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import time
88
import unittest
99

10-
from urllib3.exceptions import MaxRetryError, ConnectTimeoutError, TimeoutError as Url3TimeoutError
10+
from urllib3.exceptions import MaxRetryError, TimeoutError as Url3TimeoutError
1111

12-
from influxdb_client_3 import InfluxDBClient3, write_client_options, WriteOptions, SYNCHRONOUS, flight_client_options, \
12+
from influxdb_client_3 import InfluxDBClient3, write_client_options, WriteOptions, \
1313
WriteType, InfluxDB3ClientQueryError
1414
from influxdb_client_3.exceptions import InfluxDBError
1515
from tests.util import asyncio_run, lp_to_py_object
@@ -278,9 +278,8 @@ async def test_write_timeout_async(self):
278278
database=self.database,
279279
token=self.token,
280280
write_client_options=write_client_options(
281-
# error_callback=set_error_record,
282281
write_options=WriteOptions(
283-
max_retry_time=0, # disable retries
282+
max_retry_time=0, # disable retries
284283
timeout=20,
285284
write_type=WriteType.asynchronous
286285
)
@@ -305,7 +304,7 @@ def set_error_result(rt, rd, rx):
305304
write_client_options=write_client_options(
306305
error_callback=set_error_result,
307306
write_options=WriteOptions(
308-
max_retry_time=0, # disable retries
307+
max_retry_time=0, # disable retries
309308
timeout=20,
310309
write_type=WriteType.batching,
311310
max_retries=0,
@@ -330,11 +329,13 @@ def set_error_result(rt, rd, rx):
330329
def test_write_timeout_retry(self):
331330

332331
ErrorResult = {"rt": None, "rd": None, "rx": None}
332+
333333
def set_error_result(rt, rd, rx):
334334
nonlocal ErrorResult
335335
ErrorResult = {"rt": rt, "rd": rd, "rx": rx}
336336

337337
retry_ct = 0
338+
338339
def retry_cb(args, data, excp):
339340
nonlocal retry_ct
340341
retry_ct += 1
@@ -359,7 +360,7 @@ def retry_cb(args, data, excp):
359360

360361
lp = "test_write_timeout,location=harfa fVal=3.14,iVal=42i"
361362
localClient.write(lp)
362-
time.sleep(1) # await all retries
363+
time.sleep(1) # await all retries
363364

364365
self.assertEqual(3, retry_ct)
365366
self.assertEqual((self.database, 'default', 'ns'), ErrorResult["rt"])
@@ -391,4 +392,3 @@ def test_query_timeout_per_call_override(self):
391392

392393
with self.assertRaisesRegex(InfluxDB3ClientQueryError, ".*Deadline Exceeded.*"):
393394
localClient.query("SELECT * FROM data", timeout=0.001)
394-

tests/test_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515
from influxdb_client_3 import InfluxDBClient3
16-
from influxdb_client_3.query.query_api import QueryApiOptionsBuilder, QueryApi, QueryApiOptions
16+
from influxdb_client_3.query.query_api import QueryApiOptionsBuilder, QueryApi
1717
from influxdb_client_3.version import USER_AGENT
1818
from tests.util import asyncio_run
1919

@@ -431,7 +431,7 @@ async def fibo(iters):
431431

432432
# fibo ended before query_async
433433
assert events['query_result'] > events['fibo_end'], (f"query_result: {events['query_result']} should occur "
434-
f"after fibo_end: {events['fibo_end']}")
434+
f"after fibo_end: {events['fibo_end']}")
435435

436436
@asyncio_run
437437
async def test_query_async_timeout(self):

tests/test_write_local_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def assert_request_made(httpserver, matcher):
2323
httpserver.check_assertions()
2424

2525
@staticmethod
26-
def delay_response(httpserver, delay = 1.0):
26+
def delay_response(httpserver, delay=1.0):
2727
httpserver.expect_request(re.compile(".*")).respond_with_handler(lambda request: time.sleep(delay))
2828

2929
def test_write_default_params(self, httpserver: HTTPServer):

0 commit comments

Comments
 (0)