Skip to content

Commit

Permalink
Use temp_client() where we can't use the with_client() decorator.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek authored and aaugustin committed Jul 24, 2017
1 parent 5f09650 commit c07ff41
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions websockets/test_client_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,10 @@ def wrong_read_response(stream):
def test_server_handler_crashes(self, send):
send.side_effect = ValueError("send failed")

self.start_client()
self.loop.run_until_complete(self.client.send("Hello!"))
with self.assertRaises(ConnectionClosed):
self.loop.run_until_complete(self.client.recv())
self.stop_client()
with self.temp_client():
self.loop.run_until_complete(self.client.send("Hello!"))
with self.assertRaises(ConnectionClosed):
self.loop.run_until_complete(self.client.recv())

# Connection ends with an unexpected error.
self.assertEqual(self.client.close_code, 1011)
Expand All @@ -398,11 +397,10 @@ def test_server_handler_crashes(self, send):
def test_server_close_crashes(self, close):
close.side_effect = ValueError("close failed")

self.start_client()
self.loop.run_until_complete(self.client.send("Hello!"))
reply = self.loop.run_until_complete(self.client.recv())
self.assertEqual(reply, "Hello!")
self.stop_client()
with self.temp_client():
self.loop.run_until_complete(self.client.send("Hello!"))
reply = self.loop.run_until_complete(self.client.recv())
self.assertEqual(reply, "Hello!")

# Connection ends with an abnormal closure.
self.assertEqual(self.client.close_code, 1006)
Expand Down Expand Up @@ -431,12 +429,10 @@ def test_server_shuts_down_during_opening_handshake(self, _read_request):

@with_server()
def test_server_shuts_down_during_connection_handling(self):
self.start_client()

self.server.close()
with self.assertRaises(ConnectionClosed):
self.loop.run_until_complete(self.client.recv())
self.stop_client()
with self.temp_client():
self.server.close()
with self.assertRaises(ConnectionClosed):
self.loop.run_until_complete(self.client.recv())

# Websocket connection terminates with 1001 Going Away.
self.assertEqual(self.client.close_code, 1001)
Expand Down Expand Up @@ -465,11 +461,10 @@ def test_connection_error_during_opening_handshake(self, _read_request):
def test_connection_error_during_closing_handshake(self, close):
close.side_effect = ConnectionError

self.start_client()
self.loop.run_until_complete(self.client.send("Hello!"))
reply = self.loop.run_until_complete(self.client.recv())
self.assertEqual(reply, "Hello!")
self.stop_client()
with self.temp_client():
self.loop.run_until_complete(self.client.send("Hello!"))
reply = self.loop.run_until_complete(self.client.recv())
self.assertEqual(reply, "Hello!")

# Connection ends with an abnormal closure.
self.assertEqual(self.client.close_code, 1006)
Expand Down

0 comments on commit c07ff41

Please sign in to comment.