Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -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 | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -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 | |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 26 | #include "transport-test-common.hpp" |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 27 | |
| 28 | #include "websocket-transport-fixture.hpp" |
| 29 | |
| 30 | #include <boost/mpl/vector.hpp> |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace face { |
| 34 | namespace tests { |
| 35 | |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Face) |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 37 | BOOST_FIXTURE_TEST_SUITE(TestWebSocketTransport, IpTransportFixture<WebSocketTransportFixture>) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 38 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 39 | using WebSocketTransportFixtures = boost::mpl::vector< |
| 40 | GENERATE_IP_TRANSPORT_FIXTURE_INSTANTIATIONS(WebSocketTransportFixture) |
| 41 | >; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 42 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 43 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticProperties, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 44 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 45 | TRANSPORT_TEST_INIT(); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 46 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 47 | checkStaticPropertiesInitialized(*this->transport); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 48 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 49 | BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(ip::tcp::endpoint(this->address, 20070), "ws")); |
| 50 | BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->remoteEp, "wsclient")); |
| 51 | BOOST_CHECK_EQUAL(this->transport->getScope(), |
| 52 | this->addressScope == AddressScope::Loopback ? ndn::nfd::FACE_SCOPE_LOCAL |
| 53 | : ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 54 | BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 55 | BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 56 | BOOST_CHECK_EQUAL(this->transport->getMtu(), MTU_UNLIMITED); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(this->transport->getSendQueueCapacity(), QUEUE_UNSUPPORTED); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 60 | using StaticPropertiesV4MappedFixtures = boost::mpl::vector< |
| 61 | IpTransportFixture<WebSocketTransportFixture, AddressFamily::V4, AddressScope::Loopback>, |
| 62 | IpTransportFixture<WebSocketTransportFixture, AddressFamily::V4, AddressScope::Global> |
| 63 | >; |
| 64 | |
| 65 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticPropertiesV4Mapped, T, StaticPropertiesV4MappedFixtures, T) |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 66 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 67 | TRANSPORT_TEST_CHECK_PRECONDITIONS(); |
| 68 | auto mappedAddr = ip::address_v6::v4_mapped(this->address.to_v4()); |
| 69 | BOOST_REQUIRE(mappedAddr.is_v4_mapped()); |
| 70 | WebSocketTransportFixture::initialize(mappedAddr); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 72 | checkStaticPropertiesInitialized(*this->transport); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 73 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(ip::tcp::endpoint(mappedAddr, 20070), "ws")); |
| 75 | BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->remoteEp, "wsclient")); |
| 76 | BOOST_CHECK_EQUAL(this->transport->getScope(), |
| 77 | this->addressScope == AddressScope::Loopback ? ndn::nfd::FACE_SCOPE_LOCAL |
| 78 | : ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 79 | BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 80 | BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 81 | BOOST_CHECK_EQUAL(this->transport->getMtu(), MTU_UNLIMITED); |
Eric Newberry | 4a4ccfe | 2016-07-21 22:51:04 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(PersistencyChange) |
| 85 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 86 | TRANSPORT_TEST_INIT(); |
Davide Pesavento | 3206565 | 2017-01-15 01:52:21 -0500 | [diff] [blame] | 87 | |
| 88 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), true); |
| 89 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), false); |
| 90 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), false); |
| 91 | } |
| 92 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 93 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(PingPong, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 94 | { |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 95 | TRANSPORT_TEST_INIT(500_ms, 300_ms); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 96 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(this->limitedIo.run(2, // clientHandlePing, serverHandlePong |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 98 | 1500_ms), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 99 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 101 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPings, 1); |
| 102 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPongs, 1); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 103 | |
| 104 | this->clientShouldPong = false; |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 105 | BOOST_CHECK_EQUAL(this->limitedIo.run(2, // clientHandlePing, serverHandlePongTimeout |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 106 | 2_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 107 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 108 | BOOST_CHECK_MESSAGE(this->transport->getState() == TransportState::FAILED || |
| 109 | this->transport->getState() == TransportState::CLOSED, |
| 110 | "expected FAILED or CLOSED state, actual state=" << this->transport->getState()); |
| 111 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPings, 2); |
| 112 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPongs, 1); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 115 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Send, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 116 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 117 | TRANSPORT_TEST_INIT(); |
| 118 | |
| 119 | auto block1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 120 | this->transport->send(block1); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // clientHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 122 | 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPackets, 1); |
| 124 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutBytes, block1.size()); |
| 125 | |
| 126 | auto block2 = ndn::encoding::makeStringBlock(301, "world"); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 127 | this->transport->send(block2); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // clientHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 129 | 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutPackets, 2); |
| 131 | BOOST_CHECK_EQUAL(this->transport->getCounters().nOutBytes, block1.size() + block2.size()); |
| 132 | |
| 133 | BOOST_REQUIRE_EQUAL(this->clientReceivedMessages.size(), 2); |
| 134 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 135 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[0].data()), |
| 136 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[0].data()) + this->clientReceivedMessages[0].size(), |
| 137 | block1.begin(), block1.end()); |
| 138 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 139 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[1].data()), |
| 140 | reinterpret_cast<const uint8_t*>(this->clientReceivedMessages[1].data()) + this->clientReceivedMessages[1].size(), |
| 141 | block2.begin(), block2.end()); |
| 142 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 143 | } |
| 144 | |
| 145 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveNormal, T, WebSocketTransportFixtures, T) |
| 146 | { |
| 147 | TRANSPORT_TEST_INIT(); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 148 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 149 | auto pkt1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 150 | this->client.send(this->clientHdl, pkt1.wire(), pkt1.size(), websocketpp::frame::opcode::binary); |
| 151 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 152 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 153 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 154 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 1); |
| 155 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, pkt1.size()); |
| 156 | |
| 157 | auto pkt2 = ndn::encoding::makeStringBlock(301, "world!"); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 158 | this->client.send(this->clientHdl, pkt2.wire(), pkt2.size(), websocketpp::frame::opcode::binary); |
| 159 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 160 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 161 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 162 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 2); |
| 163 | BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, pkt1.size() + pkt2.size()); |
| 164 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 165 | |
| 166 | BOOST_REQUIRE_EQUAL(this->serverReceivedPackets->size(), 2); |
| 167 | BOOST_CHECK(this->serverReceivedPackets->at(0).packet == pkt1); |
| 168 | BOOST_CHECK(this->serverReceivedPackets->at(1).packet == pkt2); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 169 | BOOST_CHECK_EQUAL(this->serverReceivedPackets->at(0).endpoint, 0); |
| 170 | BOOST_CHECK_EQUAL(this->serverReceivedPackets->at(1).endpoint, 0); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 173 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveMalformed, T, WebSocketTransportFixtures, T) |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 174 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 175 | TRANSPORT_TEST_INIT(); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 176 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 177 | auto pkt1 = ndn::encoding::makeStringBlock(300, "hello"); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 178 | this->client.send(this->clientHdl, pkt1.wire(), pkt1.size() - 1, // truncated |
| 179 | websocketpp::frame::opcode::binary); |
| 180 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 181 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 182 | |
| 183 | // bad packet is dropped |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 184 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 185 | BOOST_CHECK_EQUAL(this->serverReceivedPackets->size(), 0); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 186 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 187 | auto pkt2 = ndn::encoding::makeStringBlock(301, "world!"); |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 188 | this->client.send(this->clientHdl, pkt2.wire(), pkt2.size(), websocketpp::frame::opcode::binary); |
| 189 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleMessage |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 190 | 1_s), LimitedIo::EXCEED_OPS); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 191 | |
| 192 | // next valid packet is still received normally |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 193 | BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); |
| 194 | BOOST_REQUIRE_EQUAL(this->serverReceivedPackets->size(), 1); |
| 195 | BOOST_CHECK(this->serverReceivedPackets->at(0).packet == pkt2); |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 198 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Close, T, WebSocketTransportFixtures, T) |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 199 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 200 | TRANSPORT_TEST_INIT(); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 201 | |
| 202 | int nStateChanges = 0; |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 203 | this->transport->afterStateChange.connect( |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 204 | [&nStateChanges] (auto oldState, auto newState) { |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 205 | switch (nStateChanges) { |
| 206 | case 0: |
| 207 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 208 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 209 | break; |
| 210 | case 1: |
| 211 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 212 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
| 213 | break; |
| 214 | default: |
| 215 | BOOST_CHECK(false); |
| 216 | } |
| 217 | nStateChanges++; |
| 218 | }); |
| 219 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 220 | this->transport->close(); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 221 | BOOST_CHECK_EQUAL(nStateChanges, 2); |
| 222 | } |
| 223 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 224 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(RemoteClose, T, WebSocketTransportFixtures, T) |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 225 | { |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 226 | TRANSPORT_TEST_INIT(); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 227 | |
| 228 | int nStateChanges = 0; |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 229 | this->transport->afterStateChange.connect( |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 230 | [&nStateChanges] (auto oldState, auto newState) { |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 231 | switch (nStateChanges) { |
| 232 | case 0: |
| 233 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 234 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 235 | break; |
| 236 | case 1: |
| 237 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 238 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
| 239 | break; |
| 240 | default: |
| 241 | BOOST_CHECK(false); |
| 242 | } |
| 243 | nStateChanges++; |
| 244 | }); |
| 245 | |
Davide Pesavento | 22fba35 | 2017-10-17 15:53:51 -0400 | [diff] [blame] | 246 | this->client.close(this->clientHdl, websocketpp::close::status::going_away, ""); |
| 247 | BOOST_CHECK_EQUAL(this->limitedIo.run(1, // serverHandleClose |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 248 | 1_s), LimitedIo::EXCEED_OPS); |
Weiwei Liu | 9360623 | 2016-02-26 16:32:11 -0700 | [diff] [blame] | 249 | |
| 250 | BOOST_CHECK_EQUAL(nStateChanges, 2); |
| 251 | } |
| 252 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 253 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SendQueueLength, T, WebSocketTransportFixtures, T) |
| 254 | { |
| 255 | TRANSPORT_TEST_INIT(); |
| 256 | |
| 257 | BOOST_CHECK_EQUAL(this->transport->getSendQueueLength(), QUEUE_UNSUPPORTED); |
| 258 | } |
| 259 | |
Yukai Tu | 2d6d563 | 2015-10-26 11:06:02 -0700 | [diff] [blame] | 260 | BOOST_AUTO_TEST_SUITE_END() // TestWebSocketTransport |
| 261 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 262 | |
| 263 | } // namespace tests |
| 264 | } // namespace face |
| 265 | } // namespace nfd |