Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 26 | #include "face/websocket-channel.hpp" |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 27 | #include "face/websocket-transport.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 29 | #include "channel-fixture.hpp" |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 30 | #include "test-ip.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 33 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | namespace tests { |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 35 | |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 36 | namespace ip = boost::asio::ip; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 38 | class WebSocketChannelFixture : public ChannelFixture<WebSocketChannel, websocket::Endpoint> |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 39 | { |
| 40 | protected: |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 41 | unique_ptr<WebSocketChannel> |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 42 | makeChannel(const ip::address& addr, uint16_t port = 0) final |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 43 | { |
| 44 | if (port == 0) |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 45 | port = getNextPort(); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 46 | |
| 47 | return make_unique<WebSocketChannel>(websocket::Endpoint(addr, port)); |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | listen(const ip::address& addr, |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 52 | const time::milliseconds& pingInterval = 10_s, |
| 53 | const time::milliseconds& pongTimeout = 1_s) |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 54 | { |
| 55 | listenerEp = websocket::Endpoint(addr, 20030); |
| 56 | listenerChannel = makeChannel(addr, 20030); |
| 57 | listenerChannel->setPingInterval(pingInterval); |
| 58 | listenerChannel->setPongTimeout(pongTimeout); |
| 59 | listenerChannel->listen(bind(&WebSocketChannelFixture::listenerOnFaceCreated, this, _1)); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | clientConnect(websocket::Client& client) |
| 64 | { |
| 65 | client.clear_access_channels(websocketpp::log::alevel::all); |
| 66 | client.clear_error_channels(websocketpp::log::elevel::all); |
| 67 | |
| 68 | client.init_asio(&g_io); |
| 69 | client.set_open_handler(bind(&WebSocketChannelFixture::clientHandleOpen, this, _1)); |
| 70 | client.set_message_handler(bind(&WebSocketChannelFixture::clientHandleMessage, this, _1, _2)); |
| 71 | client.set_ping_handler(bind(&WebSocketChannelFixture::clientHandlePing, this, _1, _2)); |
| 72 | |
| 73 | std::string uri = "ws://" + listenerEp.address().to_string() + ":" + to_string(listenerEp.port()); |
| 74 | websocketpp::lib::error_code ec; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 75 | auto con = client.get_connection(uri, ec); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 76 | BOOST_REQUIRE_EQUAL(ec, websocketpp::lib::error_code()); |
| 77 | |
| 78 | client.connect(con); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | initialize(const ip::address& addr, |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 83 | const time::milliseconds& pingInterval = 10_s, |
| 84 | const time::milliseconds& pongTimeout = 1_s) |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 85 | { |
| 86 | listen(addr, pingInterval, pongTimeout); |
| 87 | clientConnect(client); |
| 88 | BOOST_REQUIRE_EQUAL(limitedIo.run(2, // listenerOnFaceCreated, clientHandleOpen |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 89 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 90 | BOOST_REQUIRE_EQUAL(listenerChannel->size(), 1); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | clientSendInterest(const Interest& interest) |
| 95 | { |
| 96 | const Block& payload = interest.wireEncode(); |
| 97 | client.send(clientHandle, payload.wire(), payload.size(), websocketpp::frame::opcode::binary); |
| 98 | } |
| 99 | |
| 100 | private: |
| 101 | void |
| 102 | listenerOnFaceCreated(const shared_ptr<Face>& newFace) |
| 103 | { |
| 104 | BOOST_REQUIRE(newFace != nullptr); |
| 105 | newFace->afterReceiveInterest.connect(bind(&WebSocketChannelFixture::faceAfterReceiveInterest, this, _1)); |
| 106 | connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); }); |
| 107 | listenerFaces.push_back(newFace); |
| 108 | limitedIo.afterOp(); |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | faceAfterReceiveInterest(const Interest& interest) |
| 113 | { |
| 114 | faceReceivedInterests.push_back(interest); |
| 115 | limitedIo.afterOp(); |
| 116 | } |
| 117 | |
| 118 | void |
| 119 | clientHandleOpen(websocketpp::connection_hdl hdl) |
| 120 | { |
| 121 | clientHandle = hdl; |
| 122 | limitedIo.afterOp(); |
| 123 | } |
| 124 | |
| 125 | void |
| 126 | clientHandleMessage(websocketpp::connection_hdl, websocket::Client::message_ptr msg) |
| 127 | { |
| 128 | clientReceivedMessages.push_back(msg->get_payload()); |
| 129 | limitedIo.afterOp(); |
| 130 | } |
| 131 | |
| 132 | bool |
| 133 | clientHandlePing(websocketpp::connection_hdl, std::string) |
| 134 | { |
| 135 | auto now = time::steady_clock::now(); |
| 136 | if (m_prevPingRecvTime != time::steady_clock::TimePoint()) { |
| 137 | measuredPingInterval = now - m_prevPingRecvTime; |
| 138 | } |
| 139 | m_prevPingRecvTime = now; |
| 140 | |
| 141 | limitedIo.afterOp(); |
| 142 | return clientShouldPong; |
| 143 | } |
| 144 | |
| 145 | protected: |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 146 | std::vector<Interest> faceReceivedInterests; |
| 147 | |
| 148 | websocket::Client client; |
| 149 | websocketpp::connection_hdl clientHandle; |
| 150 | std::vector<std::string> clientReceivedMessages; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 151 | |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 152 | time::steady_clock::Duration measuredPingInterval; |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 153 | // set clientShouldPong to false to disable the pong response, |
| 154 | // which will eventually cause a timeout in listenerChannel |
| 155 | bool clientShouldPong = true; |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 156 | |
| 157 | private: |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 158 | time::steady_clock::TimePoint m_prevPingRecvTime; |
| 159 | }; |
| 160 | |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 161 | BOOST_AUTO_TEST_SUITE(Face) |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 162 | BOOST_FIXTURE_TEST_SUITE(TestWebSocketChannel, WebSocketChannelFixture) |
| 163 | |
| 164 | BOOST_AUTO_TEST_CASE(Uri) |
| 165 | { |
| 166 | websocket::Endpoint ep(ip::address_v4::loopback(), 20070); |
| 167 | auto channel = makeChannel(ep.address(), ep.port()); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 168 | BOOST_CHECK_EQUAL(channel->getUri(), FaceUri(ep, "ws")); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | BOOST_AUTO_TEST_CASE(Listen) |
| 172 | { |
| 173 | auto channel = makeChannel(ip::address_v4()); |
| 174 | BOOST_CHECK_EQUAL(channel->isListening(), false); |
| 175 | |
| 176 | channel->listen(nullptr); |
| 177 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 178 | |
| 179 | // listen() is idempotent |
| 180 | BOOST_CHECK_NO_THROW(channel->listen(nullptr)); |
| 181 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 182 | } |
| 183 | |
| 184 | BOOST_AUTO_TEST_CASE(MultipleAccepts) |
| 185 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 186 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 187 | SKIP_IF_IP_UNAVAILABLE(address); |
| 188 | this->listen(address); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 189 | |
| 190 | BOOST_CHECK_EQUAL(listenerChannel->isListening(), true); |
| 191 | BOOST_CHECK_EQUAL(listenerChannel->size(), 0); |
| 192 | |
| 193 | websocket::Client client1; |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 194 | this->clientConnect(client1); |
| 195 | |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(limitedIo.run(2, // listenerOnFaceCreated, clientHandleOpen |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 197 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 198 | BOOST_CHECK_EQUAL(listenerChannel->size(), 1); |
| 199 | |
| 200 | websocket::Client client2; |
| 201 | websocket::Client client3; |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 202 | this->clientConnect(client2); |
| 203 | this->clientConnect(client3); |
| 204 | |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 205 | BOOST_CHECK_EQUAL(limitedIo.run(4, // 2 listenerOnFaceCreated, 2 clientHandleOpen |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 206 | 2_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 207 | BOOST_CHECK_EQUAL(listenerChannel->size(), 3); |
| 208 | |
| 209 | // check face persistency |
| 210 | for (const auto& face : listenerFaces) { |
| 211 | BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | BOOST_AUTO_TEST_CASE(Send) |
| 216 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 217 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 218 | SKIP_IF_IP_UNAVAILABLE(address); |
| 219 | this->initialize(address); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 220 | auto transport = listenerFaces.front()->getTransport(); |
| 221 | |
| 222 | Block pkt1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 223 | transport->send(Transport::Packet(Block(pkt1))); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 224 | BOOST_CHECK_EQUAL(limitedIo.run(1, // clientHandleMessage |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 225 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 226 | |
| 227 | Block pkt2 = ndn::encoding::makeStringBlock(301, "world!"); |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 228 | transport->send(Transport::Packet(Block(pkt2))); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 229 | BOOST_CHECK_EQUAL(limitedIo.run(1, // clientHandleMessage |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 230 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 231 | |
| 232 | BOOST_REQUIRE_EQUAL(clientReceivedMessages.size(), 2); |
| 233 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 234 | reinterpret_cast<const uint8_t*>(clientReceivedMessages[0].data()), |
| 235 | reinterpret_cast<const uint8_t*>(clientReceivedMessages[0].data()) + clientReceivedMessages[0].size(), |
| 236 | pkt1.begin(), pkt1.end()); |
| 237 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 238 | reinterpret_cast<const uint8_t*>(clientReceivedMessages[1].data()), |
| 239 | reinterpret_cast<const uint8_t*>(clientReceivedMessages[1].data()) + clientReceivedMessages[1].size(), |
| 240 | pkt2.begin(), pkt2.end()); |
| 241 | } |
| 242 | |
| 243 | BOOST_AUTO_TEST_CASE(Receive) |
| 244 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 245 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 246 | SKIP_IF_IP_UNAVAILABLE(address); |
| 247 | this->initialize(address); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 248 | |
| 249 | // use network-layer packets here, otherwise GenericLinkService |
| 250 | // won't recognize the packet type and will discard it |
| 251 | auto interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 252 | auto interest2 = makeInterest("ndn:/QWiIMfj5sL"); |
| 253 | |
| 254 | clientSendInterest(*interest1); |
| 255 | BOOST_CHECK_EQUAL(limitedIo.run(1, // faceAfterReceiveInterest |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 256 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 257 | |
| 258 | clientSendInterest(*interest2); |
| 259 | BOOST_CHECK_EQUAL(limitedIo.run(1, // faceAfterReceiveInterest |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 260 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 261 | |
| 262 | BOOST_REQUIRE_EQUAL(faceReceivedInterests.size(), 2); |
| 263 | BOOST_CHECK_EQUAL(faceReceivedInterests[0].getName(), interest1->getName()); |
| 264 | BOOST_CHECK_EQUAL(faceReceivedInterests[1].getName(), interest2->getName()); |
| 265 | } |
| 266 | |
| 267 | BOOST_AUTO_TEST_CASE(FaceClosure) |
| 268 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 269 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 270 | SKIP_IF_IP_UNAVAILABLE(address); |
| 271 | this->initialize(address); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 272 | |
| 273 | listenerFaces.front()->close(); |
| 274 | BOOST_CHECK_EQUAL(listenerChannel->size(), 0); |
| 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(RemoteClose) |
| 278 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 279 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 280 | SKIP_IF_IP_UNAVAILABLE(address); |
| 281 | this->initialize(address); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 282 | |
| 283 | client.close(clientHandle, websocketpp::close::status::going_away, ""); |
| 284 | BOOST_CHECK_EQUAL(limitedIo.run(1, // faceClosedSignal |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 285 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 286 | BOOST_CHECK_EQUAL(listenerChannel->size(), 0); |
| 287 | } |
| 288 | |
| 289 | BOOST_AUTO_TEST_CASE(SetPingInterval) |
| 290 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 291 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 292 | SKIP_IF_IP_UNAVAILABLE(address); |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 293 | const auto pingInterval = 1200_ms; |
| 294 | this->initialize(address, pingInterval); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 295 | |
| 296 | BOOST_CHECK_EQUAL(limitedIo.run(2, // clientHandlePing |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 297 | pingInterval * 3), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 298 | BOOST_CHECK_LE(measuredPingInterval, pingInterval * 1.1); |
| 299 | BOOST_CHECK_GE(measuredPingInterval, pingInterval * 0.9); |
| 300 | } |
| 301 | |
| 302 | BOOST_AUTO_TEST_CASE(SetPongTimeOut) |
| 303 | { |
Davide Pesavento | b8d1fc7 | 2017-10-08 02:05:05 -0400 | [diff] [blame] | 304 | auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback); |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 305 | SKIP_IF_IP_UNAVAILABLE(address); |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 306 | this->initialize(address, 600_ms, 300_ms); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 307 | clientShouldPong = false; |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 308 | |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 309 | BOOST_CHECK_EQUAL(limitedIo.run(2, // clientHandlePing, faceClosedSignal |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 310 | 2_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 311 | BOOST_CHECK_EQUAL(listenerChannel->size(), 0); |
| 312 | |
Davide Pesavento | 0033578 | 2018-02-10 22:31:33 -0500 | [diff] [blame^] | 313 | auto transport = static_cast<WebSocketTransport*>(listenerFaces.front()->getTransport()); |
| 314 | BOOST_CHECK(transport->getState() == TransportState::FAILED || |
| 315 | transport->getState() == TransportState::CLOSED); |
| 316 | BOOST_CHECK_GE(transport->getCounters().nOutPings, 1); |
| 317 | BOOST_CHECK_LE(transport->getCounters().nOutPings, 2); |
Weiwei Liu | 280d7dd | 2016-03-02 23:19:26 -0700 | [diff] [blame] | 318 | BOOST_CHECK_EQUAL(transport->getCounters().nInPongs, 0); |
| 319 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 320 | |
| 321 | BOOST_AUTO_TEST_SUITE_END() // TestWebSocketChannel |
| 322 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 323 | |
| 324 | } // namespace tests |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 325 | } // namespace face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 326 | } // namespace nfd |