OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/websocket_transport_client_socket_pool.h" | 5 #include "net/socket/websocket_transport_client_socket_pool.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 1078 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
1079 // Now we have one socket handed out, and one pending. | 1079 // Now we have one socket handed out, and one pending. |
1080 pool_.FlushWithError(ERR_FAILED); | 1080 pool_.FlushWithError(ERR_FAILED); |
1081 EXPECT_EQ(ERR_FAILED, request(1)->WaitForResult()); | 1081 EXPECT_EQ(ERR_FAILED, request(1)->WaitForResult()); |
1082 // Socket owned by ClientSocketHandle is unaffected: | 1082 // Socket owned by ClientSocketHandle is unaffected: |
1083 EXPECT_TRUE(request(0)->handle()->socket()); | 1083 EXPECT_TRUE(request(0)->handle()->socket()); |
1084 // Return it to the pool (which deletes it). | 1084 // Return it to the pool (which deletes it). |
1085 request(0)->handle()->Reset(); | 1085 request(0)->handle()->Reset(); |
1086 } | 1086 } |
1087 | 1087 |
| 1088 // Sockets should not be leaked if CancelRequest() is called in between |
| 1089 // SetSocket() being called on the ClientSocketHandle and InvokeUserCallback(). |
| 1090 TEST_F(WebSocketTransportClientSocketPoolTest, CancelRequestReclaimsSockets) { |
| 1091 host_resolver_->set_synchronous_mode(true); |
| 1092 MockTransportClientSocketFactory::ClientSocketType socket_types[] = { |
| 1093 MockTransportClientSocketFactory::MOCK_TRIGGERABLE_CLIENT_SOCKET, |
| 1094 MockTransportClientSocketFactory::MOCK_CLIENT_SOCKET}; |
| 1095 |
| 1096 client_socket_factory_.set_client_socket_types(socket_types, |
| 1097 arraysize(socket_types)); |
| 1098 |
| 1099 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 1100 |
| 1101 base::Closure connect_trigger = |
| 1102 client_socket_factory_.WaitForTriggerableSocketCreation(); |
| 1103 |
| 1104 request(0)->handle()->Reset(); // calls CancelRequest() |
| 1105 |
| 1106 // We should now be able to create a new connection without blocking on the |
| 1107 // endpoint lock. |
| 1108 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
| 1109 } |
| 1110 |
1088 } // namespace | 1111 } // namespace |
1089 | 1112 |
1090 } // namespace net | 1113 } // namespace net |
OLD | NEW |