Skip to content

Commit

Permalink
Merge pull request #54 from julianhille/release/1.92.1
Browse files Browse the repository at this point in the history
Release 1.92.1.0 for synapse 1.92.1
  • Loading branch information
julianhille authored Nov 19, 2023
2 parents b82b97c + 7260295 commit 8d0a7af
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 38 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### [1.92.1.0] - 2023-11-19

### Updated

- Synapse to 1.92.1 (there is no matrix-synapse 1.92.0)

### [1.91.1.0] - 2023-11-19

### Updated
Expand Down Expand Up @@ -215,7 +221,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Location of github action workflow file `build.yml`
- Fix robustness for matrix-synapse name and packages changes and rebuilding in the same path (updater script)

[unreleased]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.91.1.0...HEAD
[unreleased]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.92.1.0...HEAD
[1.92.1.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.91.1.0...v1.92.1.0
[1.91.1.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.91.0.0...v1.91.1.0
[1.91.0.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.90.0.0...v1.91.0.0
[1.90.0.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.89.0.0...v1.90.0.0
Expand Down
56 changes: 54 additions & 2 deletions matrix_synapse_testutils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import hashlib
import ipaddress
import json
import logging
import os
Expand Down Expand Up @@ -45,7 +46,7 @@
from typing_extensions import ParamSpec
from zope.interface import implementer

from twisted.internet import address, threads, udp
from twisted.internet import address, tcp, threads, udp
from twisted.internet._resolver import SimpleResolverComplexifier
from twisted.internet.defer import Deferred, fail, maybeDeferred, succeed
from twisted.internet.error import DNSLookupError
Expand Down Expand Up @@ -567,6 +568,8 @@ def connectTCP(
conn = super().connectTCP(
host, port, factory, timeout=timeout, bindAddress=None
)
if self.lookups and host in self.lookups:
validate_connector(conn, self.lookups[host])

callback = self._tcp_callbacks.get((host, port))
if callback:
Expand Down Expand Up @@ -599,6 +602,55 @@ def advance(self, amount: float) -> None:
super().advance(0)


def validate_connector(connector: tcp.Connector, expected_ip: str) -> None:
"""Try to validate the obtained connector as it would happen when
synapse is running and the conection will be established.
This method will raise a useful exception when necessary, else it will
just do nothing.
This is in order to help catch quirks related to reactor.connectTCP,
since when called directly, the connector's destination will be of type
IPv4Address, with the hostname as the literal host that was given (which
could be an IPv6-only host or an IPv6 literal).
But when called from reactor.connectTCP *through* e.g. an Endpoint, the
connector's destination will contain the specific IP address with the
correct network stack class.
Note that testing code paths that use connectTCP directly should not be
affected by this check, unless they specifically add a test with a
matching reactor.lookups[HOSTNAME] = "IPv6Literal", where reactor is of
type ThreadedMemoryReactorClock.
For an example of implementing such tests, see test/handlers/send_email.py.
"""
destination = connector.getDestination()

# We use address.IPv{4,6}Address to check what the reactor thinks it is
# is sending but check for validity with ipaddress.IPv{4,6}Address
# because they fail with IPs on the wrong network stack.
cls_mapping = {
address.IPv4Address: ipaddress.IPv4Address,
address.IPv6Address: ipaddress.IPv6Address,
}

cls = cls_mapping.get(destination.__class__)

if cls is not None:
try:
cls(expected_ip)
except Exception as exc:
raise ValueError(
"Invalid IP type and resolution for %s. Expected %s to be %s"
% (destination, expected_ip, cls.__name__)
) from exc
else:
raise ValueError(
"Unknown address type %s for %s"
% (destination.__class__.__name__, destination)
)


class ThreadPool:
"""
Threadless thread pool.
Expand Down Expand Up @@ -670,7 +722,7 @@ def runInteraction(
**kwargs,
)

pool.runWithConnection = runWithConnection # type: ignore[assignment]
pool.runWithConnection = runWithConnection # type: ignore[method-assign]
pool.runInteraction = runInteraction # type: ignore[assignment]
# Replace the thread pool with a threadless 'thread' pool
pool.threadpool = ThreadPool(clock._reactor)
Expand Down
31 changes: 1 addition & 30 deletions matrix_synapse_testutils/test_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
import json
import sys
import warnings
from asyncio import Future
from binascii import unhexlify
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Optional, Tuple, TypeVar
from unittest.mock import Mock
from typing import TYPE_CHECKING, Awaitable, Callable, Tuple, TypeVar

import attr
import zope.interface
Expand Down Expand Up @@ -57,27 +55,12 @@ def get_awaitable_result(awaitable: Awaitable[TV]) -> TV:
raise Exception("awaitable has not yet completed")


def make_awaitable(result: TV) -> Awaitable[TV]:
"""
Makes an awaitable, suitable for mocking an `async` function.
This uses Futures as they can be awaited multiple times so can be returned
to multiple callers.
"""
future: Future[TV] = Future()
future.set_result(result)
return future


def setup_awaitable_errors() -> Callable[[], None]:
"""
Convert warnings from a non-awaited coroutines into errors.
"""
warnings.simplefilter("error", RuntimeWarning)

# unraisablehook was added in Python 3.8.
if not hasattr(sys, "unraisablehook"):
return lambda: None

# State shared between unraisablehook and check_for_unraisable_exceptions.
unraisable_exceptions = []
orig_unraisablehook = sys.unraisablehook
Expand All @@ -100,18 +83,6 @@ def cleanup() -> None:
return cleanup


def simple_async_mock(
return_value: Optional[TV] = None, raises: Optional[Exception] = None
) -> Mock:
# AsyncMock is not available in python3.5, this mimics part of its behaviour
async def cb(*args: Any, **kwargs: Any) -> Optional[TV]:
if raises:
raise raises
return return_value

return Mock(side_effect=cb)


# Type ignore: it does not fully implement IResponse, but is good enough for tests
@zope.interface.implementer(IResponse)
@attr.s(slots=True, frozen=True, auto_attribs=True)
Expand Down
8 changes: 4 additions & 4 deletions matrix_synapse_testutils/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class HomeserverTestCase(TestCase):
servlets: List of servlet registration function.
user_id (str): The user ID to assume if auth is hijacked.
hijack_auth: Whether to hijack auth to return the user specified
in user_id.
in user_id.
"""

hijack_auth: ClassVar[bool] = True
Expand Down Expand Up @@ -395,9 +395,9 @@ async def get_requester(*args: Any, **kwargs: Any) -> Requester:
)

# Type ignore: mypy doesn't like us assigning to methods.
self.hs.get_auth().get_user_by_req = get_requester # type: ignore[assignment]
self.hs.get_auth().get_user_by_access_token = get_requester # type: ignore[assignment]
self.hs.get_auth().get_access_token_from_request = Mock(return_value=token) # type: ignore[assignment]
self.hs.get_auth().get_user_by_req = get_requester # type: ignore[method-assign]
self.hs.get_auth().get_user_by_access_token = get_requester # type: ignore[method-assign]
self.hs.get_auth().get_access_token_from_request = Mock(return_value=token) # type: ignore[method-assign]

if self.needs_threadpool:
self.reactor.threadpool = ThreadPool() # type: ignore[assignment]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
"Topic :: Software Development"
]
dependencies = [
"matrix-synapse[test]==1.91.1"
"matrix-synapse[test]==1.92.1"
]

[project.urls]
Expand Down

0 comments on commit 8d0a7af

Please sign in to comment.