diff options
Diffstat (limited to 'test/basicserver/testbasicserver.cpp')
-rw-r--r-- | test/basicserver/testbasicserver.cpp | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 976bdd92..6f2def54 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -11,7 +11,6 @@ #include "Box.h" #include <stdio.h> -#include <unistd.h> #include <time.h> #include <typeinfo> @@ -36,6 +35,10 @@ // in ms #define COMMS_READ_TIMEOUT 4 #define COMMS_SERVER_WAIT_BEFORE_REPLYING 40 +// Use a longer timeout to give Srv2TestConversations time to write 20 MB to each of +// three child processes before starting to read it back again, without the children +// timing out and aborting. +#define SHORT_TIMEOUT 30000 class basicdaemon : public Daemon { @@ -103,6 +106,12 @@ void testservers_connection(SocketStream &rStream) } if(line == "LARGEDATA") { + // This part of the test is timing-sensitive, because we write + // 20 MB to the test and then have to wait while it reads 20 MB + // from the other two children before writing anything back to us. + // We could timeout waiting for it to talk to us again. So we + // increased the SHORT_TIMEOUT from 5 seconds to 30 to allow + // more time. { // Send lots of data char data[LARGE_DATA_BLOCK_SIZE]; @@ -112,7 +121,7 @@ void testservers_connection(SocketStream &rStream) } for(int s = 0; s < (LARGE_DATA_SIZE / LARGE_DATA_BLOCK_SIZE); ++s) { - rStream.Write(data, sizeof(data)); + rStream.Write(data, sizeof(data), SHORT_TIMEOUT); } } { @@ -120,7 +129,8 @@ void testservers_connection(SocketStream &rStream) char buf[1024]; int total = 0; int r = 0; - while(total < LARGE_DATA_SIZE && (r = rStream.Read(buf, sizeof(buf))) != 0) + while(total < LARGE_DATA_SIZE && + (r = rStream.Read(buf, sizeof(buf), SHORT_TIMEOUT)) != 0) { total += r; } @@ -142,7 +152,7 @@ void testservers_connection(SocketStream &rStream) } for(int s = 0; s < (LARGE_DATA_SIZE / LARGE_DATA_BLOCK_SIZE); ++s) { - rStream.Write(data, sizeof(data)); + rStream.Write(data, sizeof(data), SHORT_TIMEOUT); } } @@ -170,7 +180,7 @@ public: testserver() {} ~testserver() {} - void Connection(SocketStream &rStream); + void Connection(std::auto_ptr<SocketStream> apStream); virtual const char *DaemonName() const { @@ -190,9 +200,9 @@ const ConfigurationVerify *testserver::GetConfigVerify() const static ConfigurationVerify verifyserver[] = { { - "Server", - 0, - verifyserverkeys, + "Server", /* mName */ + 0, /* mpSubConfigurations */ + verifyserverkeys, /* mpKeys */ ConfigTest_Exists | ConfigTest_LastEntry, 0 } @@ -200,9 +210,9 @@ const ConfigurationVerify *testserver::GetConfigVerify() const static ConfigurationVerify verify = { - "root", - verifyserver, - 0, + "root", /* mName */ + verifyserver, /* mpSubConfigurations */ + 0, /* mpKeys */ ConfigTest_Exists | ConfigTest_LastEntry, 0 }; @@ -210,9 +220,9 @@ const ConfigurationVerify *testserver::GetConfigVerify() const return &verify; } -void testserver::Connection(SocketStream &rStream) +void testserver::Connection(std::auto_ptr<SocketStream> apStream) { - testservers_connection(rStream); + testservers_connection(*apStream); } class testProtocolServer : public testserver @@ -221,7 +231,7 @@ public: testProtocolServer() {} ~testProtocolServer() {} - void Connection(SocketStream &rStream); + void Connection(std::auto_ptr<SocketStream> apStream); virtual const char *DaemonName() const { @@ -229,9 +239,9 @@ public: } }; -void testProtocolServer::Connection(SocketStream &rStream) +void testProtocolServer::Connection(std::auto_ptr<SocketStream> apStream) { - TestProtocolServer server(rStream); + TestProtocolServer server(apStream); TestContext context; server.DoServer(context); } @@ -243,7 +253,7 @@ public: testTLSserver() {} ~testTLSserver() {} - void Connection(SocketStreamTLS &rStream); + void Connection(std::auto_ptr<SocketStreamTLS> apStream); virtual const char *DaemonName() const { @@ -283,9 +293,9 @@ const ConfigurationVerify *testTLSserver::GetConfigVerify() const return &verify; } -void testTLSserver::Connection(SocketStreamTLS &rStream) +void testTLSserver::Connection(std::auto_ptr<SocketStreamTLS> apStream) { - testservers_connection(rStream); + testservers_connection(*apStream); } @@ -336,15 +346,21 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) } for(unsigned int c = 0; c < conns.size(); ++c) { - conns[c]->Write("LARGEDATA\n", 10); + conns[c]->Write("LARGEDATA\n", 10, SHORT_TIMEOUT); } + // This part of the test is timing-sensitive, because we read 20 MB from each of + // three daemon processes, then write 20 MB to each of them, then read back + // another 20 MB from each of them. Each child could timeout waiting for us to + // read from it, or write to it, while we're servicing another child. So we + // increased the SHORT_TIMEOUT from 5 seconds to 30 to allow enough time. for(unsigned int c = 0; c < conns.size(); ++c) { // Receive lots of data char buf[1024]; int total = 0; int r = 0; - while(total < LARGE_DATA_SIZE && (r = conns[c]->Read(buf, sizeof(buf))) != 0) + while(total < LARGE_DATA_SIZE && + (r = conns[c]->Read(buf, sizeof(buf), SHORT_TIMEOUT)) != 0) { total += r; } @@ -360,7 +376,7 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) } for(int s = 0; s < (LARGE_DATA_SIZE / LARGE_DATA_BLOCK_SIZE); ++s) { - conns[c]->Write(data, sizeof(data)); + conns[c]->Write(data, sizeof(data), SHORT_TIMEOUT); } } for(unsigned int c = 0; c < conns.size(); ++c) @@ -369,7 +385,8 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) char buf[1024]; int total = 0; int r = 0; - while(total < LARGE_DATA_SIZE && (r = conns[c]->Read(buf, sizeof(buf))) != 0) + while(total < LARGE_DATA_SIZE && + (r = conns[c]->Read(buf, sizeof(buf), SHORT_TIMEOUT)) != 0) { total += r; } @@ -412,7 +429,8 @@ void TestStreamReceive(TestProtocolClient &protocol, int value, bool uncertainst while(stream->StreamDataLeft()) { // Read some data - int bytes = stream->Read(((char*)values) + bytesleft, sizeof(values) - bytesleft); + int bytes = stream->Read(((char*)values) + bytesleft, + sizeof(values) - bytesleft, SHORT_TIMEOUT); bytessofar += bytes; bytes += bytesleft; int n = bytes / 4; @@ -481,7 +499,7 @@ int test(int argc, const char *argv[]) // Launch a basic server { - std::string cmd = "./test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv1 testfiles/srv1.conf"; int pid = LaunchServer(cmd, "testfiles/srv1.pid"); @@ -527,7 +545,7 @@ int test(int argc, const char *argv[]) // Launch a test forking server { - std::string cmd = "./test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv2 testfiles/srv2.conf"; int pid = LaunchServer(cmd, "testfiles/srv2.pid"); @@ -597,7 +615,7 @@ int test(int argc, const char *argv[]) // Launch a test SSL server { - std::string cmd = "./test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv3 testfiles/srv3.conf"; int pid = LaunchServer(cmd, "testfiles/srv3.pid"); @@ -678,7 +696,7 @@ int test(int argc, const char *argv[]) //protocolserver: // Launch a test protocol handling server { - std::string cmd = "./test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv4 testfiles/srv4.conf"; int pid = LaunchServer(cmd, "testfiles/srv4.pid"); @@ -691,15 +709,15 @@ int test(int argc, const char *argv[]) TEST_THAT(ServerIsAlive(pid)); // Open a connection to it - SocketStream conn; + std::auto_ptr<SocketStream> apConn(new SocketStream); #ifdef WIN32 - conn.Open(Socket::TypeINET, "localhost", 2003); + apConn->Open(Socket::TypeINET, "localhost", 2003); #else - conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock"); + apConn->Open(Socket::TypeUNIX, "testfiles/srv4.sock"); #endif // Create a protocol - TestProtocolClient protocol(conn); + TestProtocolClient protocol(apConn); // Simple query { @@ -719,11 +737,13 @@ int test(int argc, const char *argv[]) // Try to send a stream { - CollectInBufferStream s; + std::auto_ptr<CollectInBufferStream> + s(new CollectInBufferStream()); char buf[1663]; - s.Write(buf, sizeof(buf)); - s.SetForReading(); - std::auto_ptr<TestProtocolGetStream> reply(protocol.QuerySendStream(0x73654353298ffLL, s)); + s->Write(buf, sizeof(buf)); + s->SetForReading(); + std::auto_ptr<TestProtocolGetStream> reply(protocol.QuerySendStream(0x73654353298ffLL, + (std::auto_ptr<IOStream>)s)); TEST_THAT(reply->GetStartingValue() == sizeof(buf)); } |