@@ -36,7 +36,8 @@ MATCHER(EventuallyTerminates, "") {
36
36
}
37
37
38
38
MATCHER_P (EventuallyReceives, value, " " ) {
39
- tcp::iostream *stream = const_cast <tcp::iostream *>(&arg);
39
+ std::basic_iostream<char > *stream = const_cast <std::basic_iostream<char > *>(
40
+ static_cast <const std::basic_iostream<char > *>(&arg));
40
41
std::string output;
41
42
// FIXME It should not block
42
43
(*stream) >> output;
@@ -65,7 +66,6 @@ class SocketServerTest : public Test {
65
66
66
67
virtual void SetUp () {
67
68
SocketServer* server = createListeningServer ();
68
- ASSERT_TRUE (server);
69
69
serverThread = new thread (&SocketServer::acceptOnce, server);
70
70
}
71
71
@@ -168,28 +168,31 @@ class UnixSocketServerTest : public SocketServerTest {
168
168
}
169
169
};
170
170
171
- TEST_F (UnixSocketServerTest, clientCanConnect) {
172
- // given
173
- stream_protocol::iostream client;
174
-
175
- // when
176
- client.connect (server->listenEndpoint ());
177
-
178
- // then
179
- EXPECT_THAT (client, IsConnected ());
180
- }
181
-
182
- TEST_F (UnixSocketServerTest, socketIsRemovedByDestructor) {
183
- // given
171
+ /*
172
+ * Tests are flickering on OSX when testing without traffic flowing.
173
+ *
174
+ * This full lifecycle test is not optimal but it should be enough
175
+ * given that the main difference between Unix and TCP is the socket
176
+ * created at startup and removed on shutdown.
177
+ */
178
+ TEST_F (UnixSocketServerTest, fullLifecycle) {
184
179
stream_protocol::endpoint socketName = server->listenEndpoint ();
180
+ EXPECT_CALL (protocolHandler, handle (" X" )).WillRepeatedly (Return (" Y" ));
181
+
182
+ // socket created at startup
185
183
ASSERT_TRUE (fs::exists (socketName.path ()));
186
184
187
- // when
188
- stream_protocol::iostream client (server->listenEndpoint ());
185
+ // traffic flows
186
+ stream_protocol::iostream client (socketName);
187
+ client << " X" << endl << flush;
188
+ EXPECT_THAT (client, EventuallyReceives (" Y" ));
189
+
190
+ // client disconnection terminates server
189
191
client.close ();
190
- TearDown ( );
192
+ EXPECT_THAT (serverThread, EventuallyTerminates () );
191
193
192
- // then
194
+ // socket removed by destructor
195
+ TearDown ();
193
196
EXPECT_FALSE (fs::exists (socketName.path ()));
194
197
}
195
198
#endif
0 commit comments