Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix ijson coroutines test
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Oct 31, 2022
1 parent 2eae67e commit aa291de
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/federation/transport/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import json
from unittest.mock import Mock

import ijson.common

from synapse.api.room_versions import RoomVersions
from synapse.federation.transport.client import SendJoinParser
from synapse.util import ExceptionBundle
Expand Down Expand Up @@ -117,8 +119,17 @@ def test_errors_closing_coroutines(self) -> None:
coro_3 = Mock()
coro_3.close = Mock(side_effect=RuntimeError("Couldn't close coro 3"))

original_coros = parser._coros
parser._coros = [coro_1, coro_2, coro_3]

# Close the original coroutines. If we don't, when we garbage collect them
# they will throw, failing the test. (Oddly, this only started in CPython 3.11).
for coro in original_coros:
try:
coro.close()
except ijson.common.IncompleteJSONError:
pass

# Send half of the data to the parser
parser.write(serialisation[: len(serialisation) // 2])

Expand Down

0 comments on commit aa291de

Please sign in to comment.