Skip to content

Commit 6986d64

Browse files
committed
chore: fix flake and assertion for integration test.
1 parent d047f39 commit 6986d64

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

Examples/timeouts.py

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
import sys
33
import time
44

5-
from influxdb_client_3 import InfluxDBClient3, QueryApiOptionsBuilder, WriteOptions, write_client_options
5+
from influxdb_client_3 import InfluxDBClient3
66

77

88
"""
99
This example shows how to set query and write timeouts.
1010
They can be set directly using arguments (write_timeout, query_timeout) in the client constructor.
1111
They can also be overridden in write and query calls.
1212
13-
To trigger timeout and deadline expired exceptions, reset the timeout values in the examples or
13+
To trigger timeout and deadline expired exceptions, reset the timeout values in the examples or
1414
supply new values as command line parameters.
1515
16-
Be sure to update the host, token a database values below, before running this example.
16+
Be sure to update the host, token a database values below, before running this example.
1717
"""
1818

1919
DEFAULT_WRITE_TIMEOUT = 30_000 # in milliseconds
@@ -22,49 +22,47 @@
2222
DEFAULT_TOKEN = 'my-token'
2323
DEFAULT_DATABASE = 'test-data'
2424

25-
def client_with_timeouts_via_constructor(w_to: int, q_to: int) -> InfluxDBClient3:
26-
return InfluxDBClient3(
27-
host=DEFAULT_HOST,
28-
token=DEFAULT_TOKEN,
29-
database=DEFAULT_DATABASE,
30-
write_timeout=w_to,
31-
query_timeout=q_to
32-
)
3325

34-
def client_with_timeouts_via_options(w_to: int, q_to: int) -> InfluxDBClient3:
35-
return InfluxDBClient3(
26+
def main(w_to: int, q_to: int) -> None:
27+
print(f"main {w_to}, {q_to}")
28+
lp_data = "timeout_example,location=terra fVal=3.14,iVal=42i"
29+
with InfluxDBClient3(
3630
host=DEFAULT_HOST,
3731
token=DEFAULT_TOKEN,
3832
database=DEFAULT_DATABASE,
39-
write_client_options=write_client_options(
40-
write_options=WriteOptions(timeout=w_to)
41-
),
33+
write_timeout=w_to,
4234
query_timeout=q_to
43-
)
35+
) as client:
36+
37+
try:
38+
# write with write timeout set in client
39+
client.write(record=lp_data)
40+
print("First write OK.")
41+
time.sleep(1)
42+
43+
# write overriding client internal write timeout
44+
# to force an exception try a _request_timeout value like 1 ms
45+
client.write(record=lp_data, _request_timeout=9_000)
46+
print("Second write OK.")
47+
time.sleep(1)
48+
except Exception as e:
49+
print(f"Got exception on write: {e}")
50+
51+
sql = "SELECT * FROM timeout_example"
52+
53+
try:
54+
# query using query timeout set in client
55+
result = client.query(sql)
56+
print("\nFirst query result\n", result)
57+
time.sleep(1)
58+
59+
# query overriding client internal query timeout
60+
# To force an exception try a timeout value like 0.001 seconds
61+
result = client.query(sql, timeout=3.0)
62+
print("\nSecond query result\n", result)
63+
except Exception as e:
64+
print(f"Got exception on query: {e}")
4465

45-
def main(w_to: int, q_to: int) -> None:
46-
print(f"main {w_to}, {q_to}")
47-
lp_data = "timeout_example,location=terra fVal=3.14,iVal=42i"
48-
client1 = client_with_timeouts_via_constructor(w_to, q_to)
49-
50-
# write with write timeout set in client
51-
client1.write(record=lp_data)
52-
time.sleep(1)
53-
54-
# write overriding client internal write timeout
55-
client1.write(record=lp_data, _request_timeout=9_000)
56-
time.sleep(1)
57-
58-
sql = "SELECT * FROM timeout_example"
59-
60-
# query using query timeout set in client
61-
result = client1.query(sql)
62-
print("\nFirst query result\n", result)
63-
time.sleep(1)
64-
65-
# query overriding client internal query timeout
66-
result = client1.query(sql, timeout=3.0)
67-
print("\nSecond query result\n", result)
6866

6967
if __name__ == "__main__":
7068
w_ct = DEFAULT_WRITE_TIMEOUT
@@ -76,4 +74,3 @@ def main(w_to: int, q_to: int) -> None:
7674
q_ct = int(arg)
7775

7876
main(w_ct, q_ct)
79-

tests/test_influxdb_client_3_integration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,15 @@ def retry_cb(args, data, excp):
443443
)
444444

445445
lp = "test_write_timeout,location=harfa fVal=3.14,iVal=42i"
446-
# with self.assertRaises(Url3TimeoutError):
447446
localClient.write(lp, _request_timeout=1)
448447

449448
# wait for batcher attempt last write retry
450449
time.sleep(0.1)
451450

452-
print(f"DEBUG ErrorResult {ErrorResult}, retry_ct {retry_ct}")
451+
self.assertEqual(retry_ct, 1)
452+
self.assertEqual((self.database, 'default', 'ns'), ErrorResult["rt"])
453+
self.assertIsNotNone(ErrorResult["rd"])
454+
self.assertIsInstance(ErrorResult["rd"], bytes)
455+
self.assertEqual(lp, ErrorResult["rd"].decode('utf-8'))
456+
self.assertIsNotNone(ErrorResult["rx"])
457+
self.assertIsInstance(ErrorResult["rx"], Url3TimeoutError)

0 commit comments

Comments
 (0)