Skip to content

Commit

Permalink
Check for both SocketReadError and SocketWriteError
Browse files Browse the repository at this point in the history
Depending on timing, we might get to send our message (in the test) and then
fail to read the reply, or fail during writing instead.

(cherry picked from commit 93cc703)
  • Loading branch information
qris committed Dec 8, 2017
1 parent 0d738b9 commit 95e6963
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions test/basicserver/testbasicserver.cpp
Expand Up @@ -835,9 +835,32 @@ int test(int argc, const char *argv[])
// The unexpected exception should kill the server child process that we
// connected to (except on Windows where the server does not fork a child),
// so we cannot communicate with it any more:
TEST_CHECK_THROWS(protocol.QueryQuit(),
ConnectionException, SocketWriteError);


{
bool didthrow = false;
HideExceptionMessageGuard hide;
try
{
protocol.QueryQuit();
}
catch(ConnectionException &e)
{
if(e.GetSubType() == ConnectionException::SocketReadError ||
e.GetSubType() == ConnectionException::SocketWriteError)
{
didthrow = true;
}
else
{
throw;
}
}
if(!didthrow)
{
TEST_FAIL_WITH_MESSAGE("Didn't throw expected exception");
}
}

// Kill the main server process:
TEST_THAT(KillServer(pid));
::sleep(1);
Expand Down

0 comments on commit 95e6963

Please sign in to comment.