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

Commit 0b8912a

Browse files
author
David Robertson
committed
Fix ijson coroutines test
1 parent 68a9cf6 commit 0b8912a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/federation/transport/test_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import json
1616
from unittest.mock import Mock
1717

18+
import ijson.common
19+
1820
from synapse.api.room_versions import RoomVersions
1921
from synapse.federation.transport.client import SendJoinParser
2022
from synapse.util import ExceptionBundle
@@ -117,8 +119,17 @@ def test_errors_closing_coroutines(self) -> None:
117119
coro_3 = Mock()
118120
coro_3.close = Mock(side_effect=RuntimeError("Couldn't close coro 3"))
119121

122+
original_coros = parser._coros
120123
parser._coros = [coro_1, coro_2, coro_3]
121124

125+
# Close the original coroutines. If we don't, when we garbage collect them
126+
# they will throw, failing the test. (Oddly, this only started in CPython 3.11).
127+
for coro in original_coros:
128+
try:
129+
coro.close()
130+
except ijson.common.IncompleteJSONError:
131+
pass
132+
122133
# Send half of the data to the parser
123134
parser.write(serialisation[: len(serialisation) // 2])
124135

0 commit comments

Comments
 (0)