Port Clock functions to use Duration class (#19229)
This changes the arguments in clock functions to be `Duration` and converts call sites and constants into `Duration`. There are still some more functions around that should be converted (e.g. `timeout_deferred`), but we leave that to another PR. We also changes `.as_secs()` to return a float, as the rounding broke things subtly. The only reason to keep it (its the same as `timedelta.total_seconds()`) is for symmetry with `as_millis()`. Follows on from https://github.com/element-hq/synapse/pull/19223
This commit is contained in:
@@ -30,6 +30,7 @@ from synapse.http.server import JsonResource
|
||||
from synapse.server import HomeServer
|
||||
from synapse.types import JsonDict
|
||||
from synapse.util.cancellation import cancellable
|
||||
from synapse.util.duration import Duration
|
||||
from synapse.util.ratelimitutils import FederationRateLimiter
|
||||
|
||||
from tests import unittest
|
||||
@@ -53,13 +54,13 @@ class CancellableFederationServlet(BaseFederationServlet):
|
||||
async def on_GET(
|
||||
self, origin: str, content: None, query: dict[bytes, list[bytes]]
|
||||
) -> tuple[int, JsonDict]:
|
||||
await self.clock.sleep(1.0)
|
||||
await self.clock.sleep(Duration(seconds=1))
|
||||
return HTTPStatus.OK, {"result": True}
|
||||
|
||||
async def on_POST(
|
||||
self, origin: str, content: JsonDict, query: dict[bytes, list[bytes]]
|
||||
) -> tuple[int, JsonDict]:
|
||||
await self.clock.sleep(1.0)
|
||||
await self.clock.sleep(Duration(seconds=1))
|
||||
return HTTPStatus.OK, {"result": True}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user