Skip to content

Commit

Permalink
fix: timeout can be specified as a float (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Dec 14, 2021
1 parent 0ebe302 commit 554e8a0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes
1. [#375](https://github.com/influxdata/influxdb-client-python/pull/375): Construct `InfluxDBError` without HTTP response
1. [#378](https://github.com/influxdata/influxdb-client-python/pull/378): Correct serialization DataFrame with nan values [DataFrame]
1. [#384](https://github.com/influxdata/influxdb-client-python/pull/384): Timeout can be specified as a `float`

### CI
1. [#370](https://github.com/influxdata/influxdb-client-python/pull/370): Add Python 3.10 to CI builds
Expand Down
2 changes: 1 addition & 1 deletion influxdb_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def request(self, method, url, query_params=None, headers=None,
timeout = None
_configured_timeout = _request_timeout or self.configuration.timeout
if _configured_timeout:
if isinstance(_configured_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
if isinstance(_configured_timeout, (int, float, ) if six.PY3 else (int, long, float, )): # noqa: E501,F821
timeout = urllib3.Timeout(total=_configured_timeout / 1_000)
elif (isinstance(_configured_timeout, tuple) and
len(_configured_timeout) == 2):
Expand Down
13 changes: 11 additions & 2 deletions tests/test_InfluxDBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import threading
import unittest

from urllib3.exceptions import NewConnectionError
import pytest
from urllib3.exceptions import NewConnectionError, HTTPError

from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import WriteOptions, WriteType
from influxdb_client.client.write_api import WriteOptions, WriteType, SYNCHRONOUS
from tests.base_test import BaseTest


Expand Down Expand Up @@ -166,6 +167,14 @@ def test_write_context_manager(self):
self.assertIsNone(api_client._pool)
self.assertIsNone(self.client.api_client)

def test_timeout_as_float(self):
self.client = InfluxDBClient(url="http://localhost:8088", token="my-token", org="my-org", timeout=1000.5)
self.assertEqual(1000.5, self.client.api_client.configuration.timeout)
with pytest.raises(HTTPError) as e:
write_api = self.client.write_api(write_options=SYNCHRONOUS)
write_api.write(bucket="my-bucket", org="my-org", record="mem,tag=a value=1")
self.assertIn("Failed to establish a new connection", str(e.value))


class InfluxDBClientTestIT(BaseTest):
httpRequest = []
Expand Down

0 comments on commit 554e8a0

Please sign in to comment.