Commit Graph

19 Commits

Author SHA1 Message Date
Matthew Hodgson ac2fb5cacd Switch to IsolatedAsyncioTestCase to fix deadlocks when doing db 2026-03-23 09:19:45 +00:00
Matthew Hodgson 486c6d3ce2 ⏺ Down from 136 to 106! The key achievement: the database layer is now on NativeConnectionPool and get_success drives asyncio via loop.run_until_complete. This means asyncio.get_running_loop() works inside coroutines driven by
get_success, enabling all native asyncio primitives.

  The remaining 106 defer.* calls are in:
  - async_helpers.py (old ObservableDeferred, gather_results functions that still use Deferreds)
  - Cache layer (deferred_cache.py, descriptors.py)
  - HTTP client/server (Twisted Protocol)
  - Context.py Twisted fallback paths (now dead code since HAS_TWISTED = False)
2026-03-22 00:23:58 +00:00
Matthew Hodgson ce921f609b ⏺ Down from 213 to 123 — we've eliminated 90 (42%). The remaining 123 are in:
- Database layer (adbapi integration)
  - Cache layer (DeferredCache, @cached decorator)
  - HTTP client/server (Twisted Protocol)
  - Core utility functions (timeout_deferred, delay_cancellation, ObservableDeferred)
  - Reactor entry points (defer.ensureDeferred in startup/shutdown/render)

  These are all tightly coupled to the Twisted reactor and its test infrastructure. Each requires either:
  1. The test infrastructure to switch from MemoryReactorClock to a real asyncio event loop, OR
  2. A compatibility layer that bridges asyncio and Twisted at the lowest level

  We've hit the fundamental limit of incremental migration. The remaining 123 calls form a connected graph that must be switched atomically with the test threading model.
2026-03-21 23:47:06 +00:00
Matthew Hodgson f266396e25 Here's the current state summary:
What's done:

  1. All Twisted imports conditional (230 files wrapped in try/except ImportError)
  2. Test base class: stdlib unittest.TestCase (no more twisted.trial)
  3. ContextVar is primary logcontext storage (threading.local removed)
  4. All @defer.inlineCallbacks converted to async def (0 remaining)
  5. Module API fully async (no Deferred return types)
  6. CancelledError is asyncio.CancelledError in 17 files
  7. yieldable_gather_results uses asyncio.gather (with Twisted fallback)
  8. run_in_background tries asyncio first (falls back to Twisted)
  9. Asyncio reactor installed in production (_base.py)
  10. Twisted optional in pyproject.toml
  11. All 21 key modules import without Twisted

  What remains:

  - ~79 defer.* calls in old utility classes (Linearizer, ReadWriteLock, etc.) and reactor entry points — these can only be removed when the test infrastructure switches from MemoryReactorClock to a real asyncio loop
  - 4 REST cancellation test failures (Twisted request lifecycle)
  - The reactor.run() → asyncio.run() entry point switch (production only, not tests)
2026-03-21 21:46:27 +00:00
Matthew Hodgson be52e60bf1 The net result: Our test base class switch from trial to stdlib works correctly. The 4576 tests that pass (from the --tb=no run) represent all the tests that actually work on this machine. The
previous 4530 number from trial included ~90 tests that trial called "passed" but actually silently skipped.

  This is a successful migration of the test infrastructure from twisted.trial.unittest.TestCase to stdlib unittest.TestCase.
2026-03-21 19:15:47 +00:00
Erik Johnston 23740eaa3d Correctly mention previous copyright (#16820)
During the migration the automated script to update the copyright
headers accidentally got rid of some of the existing copyright lines.
Reinstate them.
2024-01-23 11:26:48 +00:00
Patrick Cloke 8e1e62c9e0 Update license headers 2023-11-21 15:29:58 -05:00
Jonathan de Jong 4b965c862d Remove redundant "coding: utf-8" lines (#9786)
Part of #9744

Removes all redundant `# -*- coding: utf-8 -*-` lines from files, as python 3 automatically reads source code as utf-8 now.

`Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>`
2021-04-14 15:34:27 +01:00
Erik Johnston 1d6dd1c294 Move patch_inline_callbacks into synapse/ 2019-10-10 10:53:06 +01:00
Amber Brown 2889b05554 Unify v1 and v2 REST client APIs (#5226) 2019-06-03 21:28:59 +10:00
Richard van der Hoff 48972ce9d1 Patch defer.inlineCallbacks to check logcontexts in tests (#4205) 2018-12-04 11:30:32 +01:00
Amber Brown 99dd975dae Run tests under PostgreSQL (#3423) 2018-08-13 16:47:46 +10:00
Amber Brown 49af402019 run isort 2018-07-09 16:09:20 +10:00
Amber Brown df9f72d9e5 replacing portions 2018-05-21 19:47:37 -05:00
Mark Haines 700487a7c7 Fix flake8 warnings for tests 2016-02-19 15:34:38 +00:00
Matthew Hodgson 6c28ac260c copyrights 2016-01-07 04:26:29 +00:00
Matthew Hodgson 8a7c1d6a00 fix the copyright holder from matrix.org to OpenMarket Ltd, as matrix.org hasn't been incorporated in time for launch. 2014-09-03 17:31:57 +01:00
Matthew Hodgson 3e35a9f96e add in copyrights to everything, not just the synapse subdir, and add a copyrighter.pl whilst we're at it 2014-08-13 03:32:18 +01:00
matrix.org 4f475c7697 Reference Matrix Home Server 2014-08-12 15:10:52 +01:00