tests: give mock homeservers a real string hostname

The Rust `LoggingContext` requires `server_name` to be a `str`. Three test
suites built a mock homeserver whose `hostname` was left as an auto-generated
`Mock`, which flowed into `server_name` (via `DatabasePool`, `StateHandler`
and `ApplicationServicesHandler`) and raised `TypeError: argument
'server_name': 'Mock' object is not an instance of 'str'` once a
`LoggingContext`/`Measure` was constructed — 42 trial errors in CI.

Set `hostname` to the server name each suite already uses, so the mocks match
what production passes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VF56cZ93AqpuGCf8yguCcR
This commit is contained in:
Erik Johnston
2026-07-20 13:11:57 +00:00
co-authored by Claude Fable 5
parent 42f5a32f02
commit 9e75f288c2
3 changed files with 3 additions and 1 deletions
+1
View File
@@ -77,6 +77,7 @@ class AppServiceHandlerTestCase(unittest.TestCase):
self.reactor, self.clock = get_clock()
hs = Mock()
hs.hostname = "test_server"
def test_run_as_background_process(
desc: "LiteralString",
+1 -1
View File
@@ -105,7 +105,7 @@ class SQLBaseStoreTestCase(unittest.TestCase):
# To fix isinstance(...) checks.
fake_engine.__class__ = engine.__class__ # type: ignore[assignment]
db = DatabasePool(Mock(), Mock(config=db_config), fake_engine)
db = DatabasePool(Mock(hostname="test"), Mock(config=db_config), fake_engine)
db._db_pool = conn_pool
self.datastore = SQLBaseStore(db, None, hs) # type: ignore[arg-type]
+1
View File
@@ -245,6 +245,7 @@ class StateTestCase(unittest.TestCase):
)
reactor, clock = get_clock()
hs.config = default_config(server_name="tesths", parse=True)
hs.hostname = "tesths"
hs.get_datastores.return_value = Mock(
main=self.dummy_store,
state_deletion=dummy_deletion_store,