Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timedelta to ms conversion and timedelta to deadline conversion #442

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

malandis
Copy link
Contributor

@malandis malandis commented Mar 4, 2024

This PR corrects two bugs.

First we add a utility function to convert timedelta objects to milliseconds, unit tests, and refactor code to use this across the board. Previously we were converting timedeltas to milliseconds in several places which led to bugs when calling .seconds (not fractional) vs total_seconds() (fractional). Calling the former was truncating the milliseconds portion.

Second we correct a bug the gRPC timeout. After reading from the config, we converted the timedelta to total whole seconds. This again truncated the milliseconds portion; because the gRPC parameter accepts fractional seconds, we should not have been truncating.

malandis added 3 commits March 4, 2024 11:34
Because a common concern in the library is expressing a `timedelta`
object in milliseconds, we add a utility method to do that in one
place. We also add unit tests to exhaustively verify behavior.
Use utility function where appropriate. This fixes the grpc
configuration conversion which was truncating milliseconds.
Previously we were truncating the deadline to be whole seconds. This
was in error: the grpc timeout parameter accepts fractional seconds to
account for milliseconds.
@@ -154,7 +155,7 @@ def __init__(self, configuration: Configuration, credential_provider: Credential
self._endpoint = endpoint

default_deadline: timedelta = configuration.get_transport_strategy().get_grpc_configuration().get_deadline()
self._default_deadline_seconds = int(default_deadline.total_seconds())
self._default_deadline_seconds = default_deadline.total_seconds()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grpc's timeout takes fractional seconds to account for milliseconds, and timedelta.total_seconds returns fractional seconds, so we needn't truncate

@malandis malandis requested a review from a team March 4, 2024 20:33
Copy link
Contributor

@anitarua anitarua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!!

@malandis malandis merged commit 14a84ca into main Mar 4, 2024
20 checks passed
@malandis malandis deleted the fix/timedelta-to-ms-conversion branch March 4, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants