Skip to content

Commit 7d5b63c

Browse files
committed
Make test connection class less error prone.
1 parent 2715b35 commit 7d5b63c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tests/asyncio/connection.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def delay_frames_sent(self, delay):
2121
"""
2222
Add a delay before sending frames.
2323
24-
This can result in out-of-order writes, which is unrealistic.
24+
Misuse can result in out-of-order writes, which is unrealistic.
2525
2626
"""
2727
assert self.transport.delay_write is None
@@ -36,7 +36,7 @@ def delay_eof_sent(self, delay):
3636
"""
3737
Add a delay before sending EOF.
3838
39-
This can result in out-of-order writes, which is unrealistic.
39+
Misuse can result in out-of-order writes, which is unrealistic.
4040
4141
"""
4242
assert self.transport.delay_write_eof is None
@@ -83,9 +83,9 @@ class InterceptingTransport:
8383
8484
This is coupled to the implementation, which relies on these two methods.
8585
86-
Since ``write()`` and ``write_eof()`` are not coroutines, this effect is
87-
achieved by scheduling writes at a later time, after the methods return.
88-
This can easily result in out-of-order writes, which is unrealistic.
86+
Since ``write()`` and ``write_eof()`` are synchronous, we can only schedule
87+
writes at a later time, after they return. This is unrealistic and can lead
88+
to out-of-order writes if tests aren't written carefully.
8989
9090
"""
9191

@@ -101,15 +101,15 @@ def __getattr__(self, name):
101101
return getattr(self.transport, name)
102102

103103
def write(self, data):
104-
if not self.drop_write:
105-
if self.delay_write is not None:
106-
self.loop.call_later(self.delay_write, self.transport.write, data)
107-
else:
108-
self.transport.write(data)
104+
if self.delay_write is not None:
105+
assert not self.drop_write
106+
self.loop.call_later(self.delay_write, self.transport.write, data)
107+
elif not self.drop_write:
108+
self.transport.write(data)
109109

110110
def write_eof(self):
111-
if not self.drop_write_eof:
112-
if self.delay_write_eof is not None:
113-
self.loop.call_later(self.delay_write_eof, self.transport.write_eof)
114-
else:
115-
self.transport.write_eof()
111+
if self.delay_write_eof is not None:
112+
assert not self.drop_write_eof
113+
self.loop.call_later(self.delay_write_eof, self.transport.write_eof)
114+
elif not self.drop_write_eof:
115+
self.transport.write_eof()

0 commit comments

Comments
 (0)