mirror of https://github.com/zulip/zulip.git
test_tornado: Call process_event on first fetch_events return.
The 0.1 second delay was sometimes not long enough to guarantee we hit the async response path, resulting in a nondeterministic coverage failure. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
e112b619cc
commit
0430705d13
|
@ -1,8 +1,8 @@
|
|||
import asyncio
|
||||
import urllib.parse
|
||||
from functools import wraps
|
||||
from typing import Any, Awaitable, Callable, Dict, Optional, TypeVar
|
||||
from unittest import TestResult
|
||||
from typing import Any, Awaitable, Callable, Dict, Mapping, Optional, TypeVar
|
||||
from unittest import TestResult, mock
|
||||
|
||||
import orjson
|
||||
from asgiref.sync import async_to_sync, sync_to_async
|
||||
|
@ -144,8 +144,14 @@ class EventsTestCase(TornadoWebTestCase):
|
|||
)
|
||||
process_event(event, users)
|
||||
|
||||
self.io_loop.call_later(0.1, process_events)
|
||||
response = await self.client_get_async(path)
|
||||
def wrapped_fetch_events(query: Mapping[str, Any]) -> Dict[str, Any]:
|
||||
ret = event_queue.fetch_events(query)
|
||||
self.io_loop.add_callback(process_events)
|
||||
return ret
|
||||
|
||||
with mock.patch("zerver.tornado.views.fetch_events", side_effect=wrapped_fetch_events):
|
||||
response = await self.client_get_async(path)
|
||||
|
||||
self.assertEqual(response.headers["Vary"], "Accept-Language, Cookie")
|
||||
data = orjson.loads(response.body)
|
||||
self.assertEqual(
|
||||
|
|
Loading…
Reference in New Issue