1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from synapse .replication .tcp .redis import RedisDirectTcpReplicationClientFactory
15+ try :
16+ # We only import it to see if it's installed, so ignore the 'unused' import
17+ import txredisapi # noqa: F401
18+
19+ HAVE_TXREDISAPI = True
20+ except ImportError :
21+ HAVE_TXREDISAPI = False
1622
1723from tests .replication ._base import BaseMultiWorkerStreamTestCase
1824from tests .unittest import HomeserverTestCase
3844
3945
4046class RedisTestCase (HomeserverTestCase ):
47+ if not HAVE_TXREDISAPI :
48+ skip = "Redis extras not installed"
49+
4150 def test_subscribed_to_enough_redis_channels (self ) -> None :
51+ from synapse .replication .tcp .redis import RedisDirectTcpReplicationClientFactory
52+
4253 # The default main process is subscribed to USER_IP and all RDATA channels.
4354 self .assertCountEqual (
4455 RedisDirectTcpReplicationClientFactory .channels_to_subscribe_to_for_config (
@@ -52,7 +63,12 @@ def test_subscribed_to_enough_redis_channels(self) -> None:
5263
5364
5465class RedisWorkerTestCase (BaseMultiWorkerStreamTestCase ):
66+ if not HAVE_TXREDISAPI :
67+ skip = "Redis extras not installed"
68+
5569 def test_background_worker_subscribed_to_user_ip (self ) -> None :
70+ from synapse .replication .tcp .redis import RedisDirectTcpReplicationClientFactory
71+
5672 # The default main process is subscribed to USER_IP and all RDATA channels.
5773 worker1 = self .make_worker_hs (
5874 "synapse.app.generic_worker" ,
@@ -69,6 +85,8 @@ def test_background_worker_subscribed_to_user_ip(self) -> None:
6985 )
7086
7187 def test_non_background_worker_not_subscribed_to_user_ip (self ) -> None :
88+ from synapse .replication .tcp .redis import RedisDirectTcpReplicationClientFactory
89+
7290 # The default main process is subscribed to USER_IP and all RDATA channels.
7391 worker2 = self .make_worker_hs (
7492 "synapse.app.generic_worker" ,
0 commit comments