Remove MockClock() (#18992)

Spawning from adding some logcontext debug logs in
https://github.com/element-hq/synapse/pull/18966 and since we're not
logging at the `set_current_context(...)` level (see reasoning there),
this removes some usage of `set_current_context(...)`.

Specifically, `MockClock.call_later(...)` doesn't handle logcontexts
correctly. It uses the calling logcontext as the callback context
(wrong, as the logcontext could finish before the callback finishes) and
it didn't reset back to the sentinel context before handing back to the
reactor. It was like this since it was [introduced 10+ years
ago](38da9884e7).
Instead of fixing the implementation which would just be a copy of our
normal `Clock`, we can just remove `MockClock`
This commit is contained in:
Eric Eastwood
2025-09-30 11:27:29 -05:00
committed by GitHub
parent ad8dcc2119
commit 5adb08f3c9
20 changed files with 139 additions and 289 deletions

View File

@@ -29,7 +29,6 @@ from typing import (
Optional,
Set,
Tuple,
cast,
)
from unittest.mock import AsyncMock, Mock
@@ -43,12 +42,11 @@ from synapse.events.snapshot import EventContext
from synapse.state import StateHandler, StateResolutionHandler, _make_state_cache_entry
from synapse.types import MutableStateMap, StateMap
from synapse.types.state import StateFilter
from synapse.util.clock import Clock
from synapse.util.macaroons import MacaroonGenerator
from tests import unittest
from .utils import MockClock, default_config
from tests.server import get_clock
from tests.utils import default_config
_next_event_id = 1000
@@ -248,7 +246,7 @@ class StateTestCase(unittest.TestCase):
"hostname",
]
)
clock = cast(Clock, MockClock())
reactor, clock = get_clock()
hs.config = default_config("tesths", True)
hs.get_datastores.return_value = Mock(
main=self.dummy_store,