@@ -32,13 +32,13 @@ class ClientConnectionTests(unittest.IsolatedAsyncioTestCase):
3232 REMOTE = SERVER
3333
3434 async def asyncSetUp (self ):
35- loop = asyncio .get_running_loop ()
35+ self . loop = asyncio .get_running_loop ()
3636 socket_ , remote_socket = socket .socketpair ()
37- self .transport , self .connection = await loop .create_connection (
37+ self .transport , self .connection = await self . loop .create_connection (
3838 lambda : Connection (Protocol (self .LOCAL ), close_timeout = 2 * MS ),
3939 sock = socket_ ,
4040 )
41- self . remote_transport , self .remote_connection = await loop .create_connection (
41+ _remote_transport , self .remote_connection = await self . loop .create_connection (
4242 lambda : InterceptingConnection (RecordingProtocol (self .REMOTE )),
4343 sock = remote_socket ,
4444 )
@@ -710,9 +710,15 @@ async def test_close_explicit_code_reason(self):
710710 await self .assertFrameSent (Frame (Opcode .CLOSE , b"\x03 \xe9 bye!" ))
711711
712712 async def test_close_waits_for_close_frame (self ):
713- """close waits for a close frame (then EOF) before returning."""
713+ """close waits for a close frame then EOF before returning."""
714+ t0 = self .loop .time ()
714715 async with self .delay_frames_rcvd (MS ), self .delay_eof_rcvd (MS ):
715716 await self .connection .close ()
717+ t1 = self .loop .time ()
718+
719+ self .assertEqual (self .connection .state , State .CLOSED )
720+ self .assertEqual (self .connection .close_code , CloseCode .NORMAL_CLOSURE )
721+ self .assertGreater (t1 - t0 , MS )
716722
717723 with self .assertRaises (ConnectionClosedOK ) as raised :
718724 await self .connection .recv ()
@@ -726,8 +732,14 @@ async def test_close_waits_for_connection_closed(self):
726732 if self .LOCAL is SERVER :
727733 self .skipTest ("only relevant on the client-side" )
728734
735+ t0 = self .loop .time ()
729736 async with self .delay_eof_rcvd (MS ):
730737 await self .connection .close ()
738+ t1 = self .loop .time ()
739+
740+ self .assertEqual (self .connection .state , State .CLOSED )
741+ self .assertEqual (self .connection .close_code , CloseCode .NORMAL_CLOSURE )
742+ self .assertGreater (t1 - t0 , MS )
731743
732744 with self .assertRaises (ConnectionClosedOK ) as raised :
733745 await self .connection .recv ()
@@ -737,11 +749,17 @@ async def test_close_waits_for_connection_closed(self):
737749 self .assertIsNone (exc .__cause__ )
738750
739751 async def test_close_no_timeout_waits_for_close_frame (self ):
740- """close without timeout waits for a close frame ( then EOF) before returning."""
752+ """close without timeout waits for a close frame then EOF before returning."""
741753 self .connection .close_timeout = None
742754
755+ t0 = self .loop .time ()
743756 async with self .delay_frames_rcvd (MS ), self .delay_eof_rcvd (MS ):
744757 await self .connection .close ()
758+ t1 = self .loop .time ()
759+
760+ self .assertEqual (self .connection .state , State .CLOSED )
761+ self .assertEqual (self .connection .close_code , CloseCode .NORMAL_CLOSURE )
762+ self .assertGreater (t1 - t0 , MS )
745763
746764 with self .assertRaises (ConnectionClosedOK ) as raised :
747765 await self .connection .recv ()
@@ -757,8 +775,14 @@ async def test_close_no_timeout_waits_for_connection_closed(self):
757775
758776 self .connection .close_timeout = None
759777
778+ t0 = self .loop .time ()
760779 async with self .delay_eof_rcvd (MS ):
761780 await self .connection .close ()
781+ t1 = self .loop .time ()
782+
783+ self .assertEqual (self .connection .state , State .CLOSED )
784+ self .assertEqual (self .connection .close_code , CloseCode .NORMAL_CLOSURE )
785+ self .assertGreater (t1 - t0 , MS )
762786
763787 with self .assertRaises (ConnectionClosedOK ) as raised :
764788 await self .connection .recv ()
@@ -769,8 +793,14 @@ async def test_close_no_timeout_waits_for_connection_closed(self):
769793
770794 async def test_close_timeout_waiting_for_close_frame (self ):
771795 """close times out if no close frame is received."""
796+ t0 = self .loop .time ()
772797 async with self .drop_eof_rcvd (), self .drop_frames_rcvd ():
773798 await self .connection .close ()
799+ t1 = self .loop .time ()
800+
801+ self .assertEqual (self .connection .state , State .CLOSED )
802+ self .assertEqual (self .connection .close_code , CloseCode .ABNORMAL_CLOSURE )
803+ self .assertGreater (t1 - t0 , 2 * MS )
774804
775805 with self .assertRaises (ConnectionClosedError ) as raised :
776806 await self .connection .recv ()
@@ -784,8 +814,14 @@ async def test_close_timeout_waiting_for_connection_closed(self):
784814 if self .LOCAL is SERVER :
785815 self .skipTest ("only relevant on the client-side" )
786816
817+ t0 = self .loop .time ()
787818 async with self .drop_eof_rcvd ():
788819 await self .connection .close ()
820+ t1 = self .loop .time ()
821+
822+ self .assertEqual (self .connection .state , State .CLOSED )
823+ self .assertEqual (self .connection .close_code , CloseCode .NORMAL_CLOSURE )
824+ self .assertGreater (t1 - t0 , 2 * MS )
789825
790826 with self .assertRaises (ConnectionClosedOK ) as raised :
791827 await self .connection .recv ()
0 commit comments