Test: PTY MUTE/UNMUTE persists to Redis
This commit is contained in:
1 parent
ce305e957e
commit
685696b6b2
2 files changed
+48
No files matched your search
@@ -18,6 +18,7 @@ def generate_reflector_conf(name: str) -> str:
|
||||
"TG_FOR_V1_CLIENTS=999",
|
||||
f"LOCAL_PREFIX={','.join(r['prefix'])}",
|
||||
f"HTTP_SRV_PORT={T.INTERNAL_HTTP_PORT}",
|
||||
"COMMAND_PTY=/dev/shm/reflector_ctrl",
|
||||
"",
|
||||
"[SERVER_CERT]",
|
||||
f"COMMON_NAME={T.service_name(name)}",
|
||||
|
||||
@@ -174,5 +174,52 @@ class RedisTrunkFilterTest(unittest.TestCase):
|
||||
self.assertIn("TRUNK_TEST", line)
|
||||
|
||||
|
||||
class RedisPtyMuteTest(unittest.TestCase):
|
||||
SECTION = "TRUNK_TEST"
|
||||
|
||||
def setUp(self):
|
||||
flushdb()
|
||||
|
||||
def _pty_send(self, command: str) -> None:
|
||||
"""Write a command line to the reflector's PTY inside the
|
||||
container. The existing COMMAND_PTY config lives at
|
||||
/dev/shm/reflector_ctrl."""
|
||||
subprocess.run([
|
||||
"docker", "compose", "-f", "docker-compose.redis.yml",
|
||||
"exec", "-T", R1_SVC,
|
||||
"bash", "-c",
|
||||
f"printf '{command}\\n' > /dev/shm/reflector_ctrl"
|
||||
], check=True,
|
||||
cwd=os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def _wait_for_members(self, key: str, expected_cs: str, present: bool,
|
||||
timeout: float = 3.0) -> None:
|
||||
deadline = time.time() + timeout
|
||||
last = ""
|
||||
while time.time() < deadline:
|
||||
last = redis_cli("SMEMBERS", key)
|
||||
members = set(filter(None, last.splitlines()))
|
||||
if present and expected_cs in members:
|
||||
return
|
||||
if (not present) and expected_cs not in members:
|
||||
return
|
||||
time.sleep(0.1)
|
||||
self.fail(
|
||||
f"Timed out waiting for {expected_cs} "
|
||||
f"{'in' if present else 'absent from'} {key}. "
|
||||
f"Last SMEMBERS: {last!r}")
|
||||
|
||||
def test_pty_mute_then_unmute_persists_to_redis(self):
|
||||
key = k(f"trunk:{self.SECTION}:mutes")
|
||||
# Baseline: empty
|
||||
self.assertEqual(redis_cli("SMEMBERS", key), "")
|
||||
|
||||
self._pty_send(f"TRUNK MUTE {self.SECTION} SM0XYZ")
|
||||
self._wait_for_members(key, "SM0XYZ", present=True)
|
||||
|
||||
self._pty_send(f"TRUNK UNMUTE {self.SECTION} SM0XYZ")
|
||||
self._wait_for_members(key, "SM0XYZ", present=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
Reference in new issue
Block a user