public void TcpSynchronousAcceptanceTest()
{
bool serverGood = false;
Thread serverThread = new Thread(() => {
ServerThread(x => serverGood = x);
});
bool clientGood = false;
Thread clientThread = new Thread(() => {
ClientThread(x => clientGood = x);
});
clientThread.Start();
serverThread.Start();
//Sleep to allow the threads a chance to die
bool serverCompleted = serverThread.Join(5000);
bool clientCompleted = clientThread.Join(5000);
if (!(serverCompleted && clientCompleted))
{
//Politely ask both threads to stop before main thread dies and hard-aborts them
#if NET40
serverThread.Abort();
clientThread.Abort();
#endif
Assert.Fail("The threads never returned in the join");
}
else
{
Assert.IsTrue(clientGood && serverGood, "The client and server thread should have both been good");
}
}