mirror of
https://github.com/element-hq/synapse.git
synced 2026-05-25 20:44:11 +00:00
Use Duration in tests
This commit is contained in:
@@ -25,6 +25,7 @@ from synapse.rest.client import knock, login, room, sync
|
||||
from synapse.server import HomeServer
|
||||
from synapse.storage.databases.main.events import DeltaState, SlidingSyncTableChanges
|
||||
from synapse.util.clock import Clock
|
||||
from synapse.util.duration import Duration
|
||||
|
||||
from tests.rest.client.sliding_sync.test_sliding_sync import SlidingSyncBase
|
||||
from tests.test_utils.event_injection import mark_event_as_partial_state
|
||||
@@ -2281,7 +2282,7 @@ class SlidingSyncRoomsRequiredStateTestCase(SlidingSyncBase):
|
||||
sync_body,
|
||||
since=from_token,
|
||||
tok=user1_tok,
|
||||
timeout_ms=Duration(seconds=10).as_millis(),
|
||||
timeout=Duration(seconds=10),
|
||||
await_result=False,
|
||||
)
|
||||
self.reactor.advance(0.1) # Allow the request to start processing
|
||||
@@ -2300,7 +2301,7 @@ class SlidingSyncRoomsRequiredStateTestCase(SlidingSyncBase):
|
||||
]
|
||||
|
||||
response_body, _ = self.do_sync(
|
||||
sync_body, since=from_token, tok=user1_tok, timeout_ms=10_000
|
||||
sync_body, since=from_token, tok=user1_tok, timeout=Duration(seconds=10)
|
||||
)
|
||||
|
||||
# We should see the new `required_state` immediately without waiting.
|
||||
|
||||
@@ -44,6 +44,7 @@ from synapse.types import (
|
||||
StreamToken,
|
||||
)
|
||||
from synapse.util.clock import Clock
|
||||
from synapse.util.duration import Duration
|
||||
from synapse.util.stringutils import random_string
|
||||
|
||||
from tests import unittest
|
||||
@@ -87,7 +88,7 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
*,
|
||||
since: str | None = None,
|
||||
tok: str,
|
||||
timeout_ms: int | None = None,
|
||||
timeout: Duration | None = None,
|
||||
await_result: bool = True,
|
||||
) -> FakeChannel:
|
||||
"""Make a sliding sync request with given body.
|
||||
@@ -107,8 +108,8 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
query_params: dict[str, Any] = {}
|
||||
if since:
|
||||
query_params["pos"] = since
|
||||
if timeout_ms is not None:
|
||||
query_params["timeout"] = timeout_ms
|
||||
if timeout is not None:
|
||||
query_params["timeout"] = timeout.as_millis()
|
||||
|
||||
if query_params:
|
||||
query_str = urllib.parse.urlencode(query_params)
|
||||
@@ -129,7 +130,7 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
*,
|
||||
since: str | None = None,
|
||||
tok: str,
|
||||
timeout_ms: int | None = None,
|
||||
timeout: Duration | None = None,
|
||||
) -> tuple[JsonDict, str]:
|
||||
"""Do a sliding sync request with given body.
|
||||
|
||||
@@ -139,13 +140,13 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
sync_body: The full request body to use
|
||||
since: Optional since token
|
||||
tok: Access token to use
|
||||
timeout_ms: Optional timeout in milliseconds to use for the request.
|
||||
timeout: Optional timeout to use for the request.
|
||||
|
||||
Returns:
|
||||
A tuple of the response body and the `pos` field.
|
||||
"""
|
||||
channel = self.make_sync_request(
|
||||
sync_body, since=since, tok=tok, timeout_ms=timeout_ms
|
||||
sync_body, since=since, tok=tok, timeout=timeout
|
||||
)
|
||||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user