File: 0007-Fix-test-reactor-imports.patch

package info (click to toggle)
matrix-synapse 1.139.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,164 kB
  • sloc: python: 257,322; javascript: 7,311; sql: 4,727; sh: 1,177; perl: 626; makefile: 207
file content (147 lines) | stat: -rw-r--r-- 6,333 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
From: Antonio Russo <aerusso@aerusso.net>
Date: Fri, 22 Sep 2023 05:53:17 -0600
Subject: Fix test reactor imports

Forwarded: no

Some twisted modules fail to function correctly if import at test import time.
For whatever reason, this problem does not occur if they are imported are test
run time.

I have not (yet?) diagnosed the actual cause, so this is not suitable for
upstream submission, but this does get our tests working.
---
 tests/federation/transport/server/test__base.py | 3 ++-
 tests/http/test_servlet.py                      | 3 ++-
 tests/replication/http/test__base.py            | 3 ++-
 tests/test_server.py                            | 5 ++++-
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/tests/federation/transport/server/test__base.py b/tests/federation/transport/server/test__base.py
index 0e3b41e..7299475 100644
--- a/tests/federation/transport/server/test__base.py
+++ b/tests/federation/transport/server/test__base.py
@@ -34,7 +34,6 @@ from synapse.util.cancellation import cancellable
 from synapse.util.ratelimitutils import FederationRateLimiter
 
 from tests import unittest
-from tests.http.server._base import test_disconnect
 
 
 class CancellableFederationServlet(BaseFederationServlet):
@@ -94,6 +93,7 @@ class BaseFederationServletCancellationTests(unittest.FederatingHomeserverTestCa
         # request won't be processed.
         self.pump()
 
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
@@ -114,6 +114,7 @@ class BaseFederationServletCancellationTests(unittest.FederatingHomeserverTestCa
         # request won't be processed.
         self.pump()
 
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
diff --git a/tests/http/test_servlet.py b/tests/http/test_servlet.py
index db39ecf..c084871 100644
--- a/tests/http/test_servlet.py
+++ b/tests/http/test_servlet.py
@@ -37,7 +37,6 @@ from synapse.types import JsonDict
 from synapse.util.cancellation import cancellable
 
 from tests import unittest
-from tests.http.server._base import test_disconnect
 
 
 def make_request(content: Union[bytes, JsonDict]) -> Mock:
@@ -127,6 +126,7 @@ class TestRestServletCancellation(unittest.HomeserverTestCase):
     def test_cancellable_disconnect(self) -> None:
         """Test that handlers with the `@cancellable` flag can be cancelled."""
         channel = self.make_request("GET", "/sleep", await_result=False)
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
@@ -137,6 +137,7 @@ class TestRestServletCancellation(unittest.HomeserverTestCase):
     def test_uncancellable_disconnect(self) -> None:
         """Test that handlers without the `@cancellable` flag cannot be cancelled."""
         channel = self.make_request("POST", "/sleep", await_result=False)
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
diff --git a/tests/replication/http/test__base.py b/tests/replication/http/test__base.py
index 31d3163..a472841 100644
--- a/tests/replication/http/test__base.py
+++ b/tests/replication/http/test__base.py
@@ -33,7 +33,6 @@ from synapse.types import JsonDict
 from synapse.util.cancellation import cancellable
 
 from tests import unittest
-from tests.http.server._base import test_disconnect
 
 
 class CancellableReplicationEndpoint(ReplicationEndpoint):
@@ -94,6 +93,7 @@ class ReplicationEndpointCancellationTestCase(unittest.HomeserverTestCase):
         """Test that handlers with the `@cancellable` flag can be cancelled."""
         path = f"{REPLICATION_PREFIX}/{CancellableReplicationEndpoint.NAME}/"
         channel = self.make_request("POST", path, await_result=False, content={})
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
@@ -105,6 +105,7 @@ class ReplicationEndpointCancellationTestCase(unittest.HomeserverTestCase):
         """Test that handlers without the `@cancellable` flag cannot be cancelled."""
         path = f"{REPLICATION_PREFIX}/{UncancellableReplicationEndpoint.NAME}/"
         channel = self.make_request("POST", path, await_result=False, content={})
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
diff --git a/tests/test_server.py b/tests/test_server.py
index 69efcea..4c65623 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -40,7 +40,6 @@ from synapse.util.cancellation import cancellable
 from synapse.util.clock import Clock
 
 from tests import unittest
-from tests.http.server._base import test_disconnect
 from tests.server import (
     FakeChannel,
     FakeSite,
@@ -445,6 +444,7 @@ class DirectServeJsonResourceCancellationTests(unittest.TestCase):
         channel = make_request(
             self.reactor, self.site, "GET", "/sleep", await_result=False
         )
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
@@ -457,6 +457,7 @@ class DirectServeJsonResourceCancellationTests(unittest.TestCase):
         channel = make_request(
             self.reactor, self.site, "POST", "/sleep", await_result=False
         )
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
@@ -479,6 +480,7 @@ class DirectServeHtmlResourceCancellationTests(unittest.TestCase):
         channel = make_request(
             self.reactor, self.site, "GET", "/sleep", await_result=False
         )
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor,
             channel,
@@ -491,6 +493,7 @@ class DirectServeHtmlResourceCancellationTests(unittest.TestCase):
         channel = make_request(
             self.reactor, self.site, "POST", "/sleep", await_result=False
         )
+        from tests.http.server._base import test_disconnect
         test_disconnect(
             self.reactor, channel, expect_cancellation=False, expected_body=b"ok"
         )