Commit 47a84d2e authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add a test checking bad bytes cause a shutdown

parent 66fbd4b4
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -235,6 +235,30 @@ class SendMessageTests(unittest.TestCase):
			# At this point the response to SOME_COMMAND1 is still delayed
			await client.send_command("SOME_COMMAND2", expect="REPLY2")

	@anyio_mock.with_anyio()
	async def test_multi_task_decode_error(self):
		"""
		Check that decode errors closes the socket and causes all tasks to raise EOFError
		"""
		recv_responses = [
			b"OK",           # Response to ATTACH
			b"\xa5\x8b",     # Undecodable input
			anyio.EndOfStream,
			anyio.EndOfStream,
		]

		async with self.client as client, anyio.create_task_group() as task_group:
			client.sock.receive.side_effect = recv_responses

			@task_group.start_soon
			async def wait_for_event():
				with self.assertRaises(anyio.ClosedResourceError):
					await client.event("CTRL-FOO"),
			await anyio.sleep(0.1)  # Ensure send_command("ATTACH") has been sent

			with self.assertRaises(anyio.ClosedResourceError):
				await client.send_command("SOME_COMMAND", expect="REPLY")


class EventTests(unittest.TestCase):
	"""