|
1 | 1 | """Unit tests for langflow.core.celeryconfig module.""" |
2 | 2 |
|
| 3 | +import importlib |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
3 | 7 | # Import the module to test |
4 | 8 | from langflow.core import celeryconfig |
5 | 9 |
|
6 | 10 |
|
| 11 | +@pytest.fixture(autouse=True) |
| 12 | +def _restore_celeryconfig_after_test(monkeypatch): |
| 13 | + yield |
| 14 | + monkeypatch.undo() |
| 15 | + importlib.reload(celeryconfig) |
| 16 | + |
| 17 | + |
7 | 18 | class TestCeleryConfigAcceptContent: |
8 | 19 | """Unit tests for accept_content configuration.""" |
9 | 20 |
|
@@ -93,3 +104,51 @@ def test_result_backend_contains_host(self): |
93 | 104 | if "://" in result_backend: |
94 | 105 | host_part = result_backend.split("://")[1] |
95 | 106 | assert len(host_part) > 0 |
| 107 | + |
| 108 | + |
| 109 | +class TestCeleryConfigValkey: |
| 110 | + """Unit tests for Valkey broker configuration.""" |
| 111 | + |
| 112 | + def test_valkey_env_vars_set_broker_and_backend(self, monkeypatch): |
| 113 | + monkeypatch.setenv("LANGFLOW_VALKEY_HOST", "valkey-host") |
| 114 | + monkeypatch.setenv("LANGFLOW_VALKEY_PORT", "6380") |
| 115 | + monkeypatch.delenv("LANGFLOW_REDIS_HOST", raising=False) |
| 116 | + monkeypatch.delenv("LANGFLOW_REDIS_PORT", raising=False) |
| 117 | + |
| 118 | + importlib.reload(celeryconfig) |
| 119 | + |
| 120 | + assert celeryconfig.broker_url == "redis://valkey-host:6380/0" |
| 121 | + assert celeryconfig.result_backend == "redis://valkey-host:6380/0" |
| 122 | + |
| 123 | + def test_valkey_takes_precedence_over_redis(self, monkeypatch): |
| 124 | + monkeypatch.setenv("LANGFLOW_VALKEY_HOST", "valkey-host") |
| 125 | + monkeypatch.setenv("LANGFLOW_VALKEY_PORT", "6380") |
| 126 | + monkeypatch.setenv("LANGFLOW_REDIS_HOST", "redis-host") |
| 127 | + monkeypatch.setenv("LANGFLOW_REDIS_PORT", "6379") |
| 128 | + |
| 129 | + importlib.reload(celeryconfig) |
| 130 | + |
| 131 | + assert celeryconfig.broker_url == "redis://valkey-host:6380/0" |
| 132 | + assert celeryconfig.result_backend == "redis://valkey-host:6380/0" |
| 133 | + |
| 134 | + def test_without_valkey_preserves_redis_behavior(self, monkeypatch): |
| 135 | + monkeypatch.delenv("LANGFLOW_VALKEY_HOST", raising=False) |
| 136 | + monkeypatch.delenv("LANGFLOW_VALKEY_PORT", raising=False) |
| 137 | + monkeypatch.setenv("LANGFLOW_REDIS_HOST", "redis-host") |
| 138 | + monkeypatch.setenv("LANGFLOW_REDIS_PORT", "6379") |
| 139 | + |
| 140 | + importlib.reload(celeryconfig) |
| 141 | + |
| 142 | + assert celeryconfig.broker_url == "redis://redis-host:6379/0" |
| 143 | + assert celeryconfig.result_backend == "redis://redis-host:6379/0" |
| 144 | + |
| 145 | + def test_incomplete_valkey_configuration_falls_back_to_redis(self, monkeypatch): |
| 146 | + monkeypatch.setenv("LANGFLOW_VALKEY_HOST", "valkey-host") |
| 147 | + monkeypatch.delenv("LANGFLOW_VALKEY_PORT", raising=False) |
| 148 | + monkeypatch.setenv("LANGFLOW_REDIS_HOST", "redis-host") |
| 149 | + monkeypatch.setenv("LANGFLOW_REDIS_PORT", "6379") |
| 150 | + |
| 151 | + importlib.reload(celeryconfig) |
| 152 | + |
| 153 | + assert celeryconfig.broker_url == "redis://redis-host:6379/0" |
| 154 | + assert celeryconfig.result_backend == "redis://redis-host:6379/0" |
0 commit comments