Skip to content

Commit edb9060

Browse files
committed
Fixed flickering Unix socket tests on OSX
1 parent b162c41 commit edb9060

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

tests/integration/WireServerTest.cpp

+22-19
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ MATCHER(EventuallyTerminates, "") {
3636
}
3737

3838
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));
4041
std::string output;
4142
// FIXME It should not block
4243
(*stream) >> output;
@@ -65,7 +66,6 @@ class SocketServerTest : public Test {
6566

6667
virtual void SetUp() {
6768
SocketServer* server = createListeningServer();
68-
ASSERT_TRUE(server);
6969
serverThread = new thread(&SocketServer::acceptOnce, server);
7070
}
7171

@@ -168,28 +168,31 @@ class UnixSocketServerTest : public SocketServerTest {
168168
}
169169
};
170170

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) {
184179
stream_protocol::endpoint socketName = server->listenEndpoint();
180+
EXPECT_CALL(protocolHandler, handle("X")).WillRepeatedly(Return("Y"));
181+
182+
// socket created at startup
185183
ASSERT_TRUE(fs::exists(socketName.path()));
186184

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
189191
client.close();
190-
TearDown();
192+
EXPECT_THAT(serverThread, EventuallyTerminates());
191193

192-
// then
194+
// socket removed by destructor
195+
TearDown();
193196
EXPECT_FALSE(fs::exists(socketName.path()));
194197
}
195198
#endif

0 commit comments

Comments
 (0)