Skip to content

Commit

Permalink
Added some tests for a failed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
pp81381 committed Aug 15, 2020
1 parent 4d6b277 commit f1e49d2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rsp1570serial/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
INITIAL_SOURCE,
INITIAL_VOLUME,
)
from serial import SerialException

TEST_PORT = 50050
BAD_TEST_PORT = TEST_PORT + 1


@asynccontextmanager
Expand Down Expand Up @@ -121,3 +123,20 @@ async def test_multi_clients1(self):
self.assertEqual(conn1.queue.qsize(), 3)
self.assertEqual(conn3.queue.qsize(), 3)

async def test_connection_failure1(self):
shared_conn = SharedRotelAmpConn(f"socket://:{BAD_TEST_PORT}")
with self.assertRaises(SerialException):
# Connection refused by host
await shared_conn.open()

async def test_connection_failure2(self):
shared_conn = SharedRotelAmpConn(f"socket://192.168.51.1:{TEST_PORT}")
with self.assertRaises(SerialException):
# Timed out due to made up IP address
await shared_conn.open()

async def test_connection_failure3(self):
shared_conn = SharedRotelAmpConn(f"socket://made_up_hostname:{TEST_PORT}")
with self.assertRaises(SerialException):
# getaddrinfo failed
await shared_conn.open()

0 comments on commit f1e49d2

Please sign in to comment.