Added chatterbox connections
This commit is contained in:
1 parent
41ef12f954
commit
e58ceeb192
58 files changed
+8931
-8
No files matched your search
@@ -0,0 +1,38 @@
|
||||
"""Tests for lab startup failure handling. No SDK or network required."""
|
||||
import contextlib
|
||||
import io
|
||||
import unittest
|
||||
from unittest.mock import patch, Mock
|
||||
import lab
|
||||
|
||||
class RunnerTests(unittest.TestCase):
|
||||
def test_missing_sdk_fails_before_starting(self):
|
||||
with patch.object(lab.shutil, "which", return_value=None), \
|
||||
patch.object(lab.subprocess, "Popen") as spawn, \
|
||||
patch.object(lab.sys, "argv", ["lab.py", "start"]), \
|
||||
contextlib.redirect_stdout(io.StringIO()):
|
||||
self.assertEqual(lab.main(), 1)
|
||||
spawn.assert_not_called()
|
||||
|
||||
def test_cleanup_when_cabinet_launch_fails(self):
|
||||
broker = Mock()
|
||||
broker.poll.return_value = None
|
||||
with patch.object(lab.socket, "socket"), \
|
||||
patch.object(lab.socket, "create_connection"), \
|
||||
patch.object(lab.Path, "exists", return_value=True), \
|
||||
patch.object(lab.shutil, "which", return_value="nats-server"), \
|
||||
patch.object(lab.subprocess, "Popen", side_effect=[broker, OSError("launch failed")]):
|
||||
with self.assertRaises(OSError):
|
||||
lab.start()
|
||||
broker.terminate.assert_called_once()
|
||||
broker.wait.assert_called_once()
|
||||
|
||||
def test_command_identity_and_expiry(self):
|
||||
first = lab.command("scan", "session")
|
||||
second = lab.command("scan", "session")
|
||||
self.assertNotEqual(first["id"], second["id"])
|
||||
self.assertEqual(first["session"], "session")
|
||||
self.assertGreater(first["expires_ms"], int(lab.time.time() * 1000))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user