Commit 66fbd4b4 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Rework timings of command interference test

parent 21c55db7
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -206,16 +206,17 @@ class SendMessageTests(unittest.TestCase):
		Check that calling send_command() from multiple tasks works as expected
		"""
		recv_responses = iter([
			b"OK",           # Response to ATTACH
			b"OK",           # Response to SOME_COMMAND1
			b"<2>CTRL-FOO",  # Event
			b"REPLY2",       # Response to SOME_COMMAND2
			b"OK",           # Response to DETACH
			(0.0, b"OK"),           # Response to ATTACH
			(0.5, b"OK"),           # Response to SOME_COMMAND1
			(0.2, b"<2>CTRL-FOO"),  # Event
			(0.1, b"REPLY2"),       # Response to SOME_COMMAND2
			(0.0, b"OK"),           # Response to DETACH
		])

		async def recv():
			await anyio.sleep(0.1)
			return next(recv_responses)
			delay, data = next(recv_responses)
			await anyio.sleep(delay)
			return data

		async with self.client as client, anyio.create_task_group() as task_group:
			client.sock.receive.side_effect = recv
@@ -226,11 +227,12 @@ class SendMessageTests(unittest.TestCase):
					await client.event("CTRL-FOO"),
					(base.EventPriority.INFO, "CTRL-FOO", None),
				)
			await anyio.sleep(0.1)  # Ensure send_command("ATTACH") has been sent

			await anyio.sleep(0.0)
			task_group.start_soon(client.send_command, "SOME_COMMAND1")
			await anyio.sleep(0.1)  # Ensure send_command("SOME_COMMAND1") has been sent

			await anyio.sleep(0.0)
			# At this point the response to SOME_COMMAND1 is still delayed
			await client.send_command("SOME_COMMAND2", expect="REPLY2")