Skip to content

Commit

Permalink
fix: convert DAPR_HEALTH_TIMEOUT to float (#692)
Browse files Browse the repository at this point in the history
* fix: convert DAPR_HEALTH_TIMEOUT to float

Signed-off-by: KentHsu <chiahaohsu9@gmail.com>

* test: update healthcheck timeout mock to a float value

Signed-off-by: KentHsu <chiahaohsu9@gmail.com>

---------

Signed-off-by: KentHsu <chiahaohsu9@gmail.com>
Co-authored-by: Bernd Verst <github@bernd.dev>
  • Loading branch information
KentHsu and berndverst authored Apr 30, 2024
1 parent 9021b95 commit 9d3fdbc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dapr/clients/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def wait_until_ready():
headers = {USER_AGENT_HEADER: DAPR_USER_AGENT}
if settings.DAPR_API_TOKEN is not None:
headers[DAPR_API_TOKEN_HEADER] = settings.DAPR_API_TOKEN
timeout = settings.DAPR_HEALTH_TIMEOUT
timeout = float(settings.DAPR_HEALTH_TIMEOUT)

start = time.time()
while True:
Expand Down
4 changes: 2 additions & 2 deletions tests/clients/test_heatlhcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_wait_until_ready_success_with_api_token(self, mock_urlopen):
self.assertIn('Dapr-api-token', headers)
self.assertEqual(headers['Dapr-api-token'], 'mytoken')

@patch.object(settings, 'DAPR_HEALTH_TIMEOUT', 2)
@patch.object(settings, 'DAPR_HEALTH_TIMEOUT', '2.5')
@patch('urllib.request.urlopen')
def test_wait_until_ready_timeout(self, mock_urlopen):
mock_urlopen.return_value.__enter__.return_value = MagicMock(status=500)
Expand All @@ -72,5 +72,5 @@ def test_wait_until_ready_timeout(self, mock_urlopen):
with self.assertRaises(TimeoutError):
DaprHealth.wait_until_ready()

self.assertGreaterEqual(time.time() - start, 2)
self.assertGreaterEqual(time.time() - start, 2.5)
self.assertGreater(mock_urlopen.call_count, 1)

0 comments on commit 9d3fdbc

Please sign in to comment.