MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / TEST

Function TEST

source/test/universe_connection_test.cpp:98–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96};
97
98TEST(UniverseConnections, All) {
99 UniverseConnectionServer server([](UniverseConnectionServer* server, ConnectionId clientId, List<PacketPtr> packets) {
100 server->sendPackets(clientId, packets);
101 });
102
103 ConnectionId clientId = ServerConnectionId;
104 TcpServer tcpServer(HostAddressWithPort(HostAddress::localhost(), ServerPort));
105 tcpServer.setAcceptCallback([&server, &clientId](TcpSocketPtr socket) {
106 socket->setNonBlocking(true);
107 auto conn = UniverseConnection(TcpPacketSocket::open(std::move(socket)));
108 server.addConnection(++clientId, std::move(conn));
109 });
110
111 LinkedList<ASyncClientThread> localASyncClients;
112 for (unsigned i = 0; i < NumLocalASyncConnections; ++i) {
113 auto pair = LocalPacketSocket::openPair();
114 server.addConnection(++clientId, UniverseConnection(std::move(pair.first)));
115 localASyncClients.emplaceAppend(UniverseConnection(std::move(pair.second)));
116 }
117
118 LinkedList<SyncClientThread> localSyncClients;
119 for (unsigned i = 0; i < NumLocalSyncConnections; ++i) {
120 auto pair = LocalPacketSocket::openPair();
121 server.addConnection(++clientId, UniverseConnection(std::move(pair.first)));
122 localSyncClients.emplaceAppend(UniverseConnection(std::move(pair.second)));
123 }
124
125 LinkedList<ASyncClientThread> remoteASyncClients;
126 for (unsigned i = 0; i < NumRemoteASyncConnections; ++i) {
127 auto socket = TcpSocket::connectTo({HostAddress::localhost(), ServerPort});
128 socket->setNonBlocking(true);
129 remoteASyncClients.emplaceAppend(UniverseConnection(TcpPacketSocket::open(std::move(socket))));
130 }
131
132 LinkedList<SyncClientThread> remoteSyncClients;
133 for (unsigned i = 0; i < NumRemoteSyncConnections; ++i) {
134 auto socket = TcpSocket::connectTo({HostAddress::localhost(), ServerPort});
135 socket->setNonBlocking(true);
136 remoteSyncClients.emplaceAppend(UniverseConnection(TcpPacketSocket::open(std::move(socket))));
137 }
138
139 for (auto& c : localASyncClients)
140 c.join();
141
142 for (auto& c : remoteASyncClients)
143 c.join();
144
145 for (auto& c : localSyncClients)
146 c.join();
147
148 for (auto& c : remoteSyncClients)
149 c.join();
150
151 server.removeAllConnections();
152}

Callers

nothing calls this directly

Calls 9

HostAddressWithPortClass · 0.85
UniverseConnectionClass · 0.85
setAcceptCallbackMethod · 0.80
setNonBlockingMethod · 0.80
addConnectionMethod · 0.80
emplaceAppendMethod · 0.80
removeAllConnectionsMethod · 0.80
sendPacketsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected