summaryrefslogtreecommitdiff
path: root/test/basicserver
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2018-02-20 21:49:13 -0500
committerReinhard Tartler <siretart@tauware.de>2018-02-20 21:49:13 -0500
commitf28f88e5e72ba1499409047a9d6985eb312c0232 (patch)
treec9c267f18264b3dfe715a363935bb6ac20904492 /test/basicserver
parente19a5db232e1ef90e9a02159d2fbd9707ffe4373 (diff)
parent6d7e9562e8485591a4888f1fc2d3c6c657dc7a01 (diff)
Merge tag 'BoxBackup-0.12.master.180102.6d7e956' into upstream
Diffstat (limited to 'test/basicserver')
-rw-r--r--test/basicserver/Makefile.extra6
-rw-r--r--test/basicserver/TestCommands.cpp25
-rw-r--r--test/basicserver/TestProtocol.txt (renamed from test/basicserver/testprotocol.txt)0
-rw-r--r--test/basicserver/testbasicserver.cpp92
4 files changed, 75 insertions, 48 deletions
diff --git a/test/basicserver/Makefile.extra b/test/basicserver/Makefile.extra
index e6a4675e..4b21d37d 100644
--- a/test/basicserver/Makefile.extra
+++ b/test/basicserver/Makefile.extra
@@ -1,12 +1,12 @@
MAKEPROTOCOL = ../../lib/server/makeprotocol.pl
-GEN_CMD = $(MAKEPROTOCOL) testprotocol.txt
+GEN_CMD = $(MAKEPROTOCOL) TestProtocol.txt
# AUTOGEN SEEDING
-autogen_TestProtocol.cpp: $(MAKEPROTOCOL) testprotocol.txt
+autogen_TestProtocol.cpp: $(MAKEPROTOCOL) TestProtocol.txt
$(_PERL) $(GEN_CMD)
-autogen_TestProtocolServer.h: $(MAKEPROTOCOL) testprotocol.txt
+autogen_TestProtocolServer.h: $(MAKEPROTOCOL) TestProtocol.txt
$(_PERL) $(GEN_CMD)
diff --git a/test/basicserver/TestCommands.cpp b/test/basicserver/TestCommands.cpp
index 5238819f..bdbdffeb 100644
--- a/test/basicserver/TestCommands.cpp
+++ b/test/basicserver/TestCommands.cpp
@@ -11,6 +11,11 @@
#include "MemLeakFindOn.h"
+std::auto_ptr<TestProtocolMessage> TestProtocolReplyable::HandleException(BoxException& e) const
+{
+ throw;
+}
+
std::auto_ptr<TestProtocolMessage> TestProtocolHello::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const
{
if(mNumber32 != 41 || mNumber16 != 87 || mNumber8 != 11 || mText != "pingu")
@@ -48,7 +53,8 @@ public:
std::auto_ptr<TestProtocolMessage> TestProtocolGetStream::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const
{
// make a new stream object
- CollectInBufferStream *pstream = mUncertainSize?(new UncertainBufferStream):(new CollectInBufferStream);
+ std::auto_ptr<CollectInBufferStream> apStream(
+ mUncertainSize?(new UncertainBufferStream):(new CollectInBufferStream));
// Data.
int values[24273];
@@ -59,19 +65,21 @@ std::auto_ptr<TestProtocolMessage> TestProtocolGetStream::DoCommand(TestProtocol
{
values[x] = v++;
}
- pstream->Write(values, sizeof(values));
+ apStream->Write(values, sizeof(values));
}
// Finished
- pstream->SetForReading();
+ apStream->SetForReading();
// Get it to be sent
- rProtocol.SendStreamAfterCommand(pstream);
+ rProtocol.SendStreamAfterCommand((std::auto_ptr<IOStream>)apStream);
return std::auto_ptr<TestProtocolMessage>(new TestProtocolGetStream(mStartingValue, mUncertainSize));
}
-std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(TestProtocolReplyable &rProtocol, TestContext &rContext) const
+std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(
+ TestProtocolReplyable &rProtocol, TestContext &rContext,
+ IOStream& rDataStream) const
{
if(mValue != 0x73654353298ffLL)
{
@@ -79,15 +87,14 @@ std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(TestProtoco
}
// Get a stream
- std::auto_ptr<IOStream> stream(rProtocol.ReceiveStream());
- bool uncertain = (stream->BytesLeftToRead() == IOStream::SizeOfStreamUnknown);
+ bool uncertain = (rDataStream.BytesLeftToRead() == IOStream::SizeOfStreamUnknown);
// Count how many bytes in it
int bytes = 0;
char buffer[125];
- while(stream->StreamDataLeft())
+ while(rDataStream.StreamDataLeft())
{
- bytes += stream->Read(buffer, sizeof(buffer));
+ bytes += rDataStream.Read(buffer, sizeof(buffer));
}
// tell the caller how many bytes there were
diff --git a/test/basicserver/testprotocol.txt b/test/basicserver/TestProtocol.txt
index 5bca9f49..5bca9f49 100644
--- a/test/basicserver/testprotocol.txt
+++ b/test/basicserver/TestProtocol.txt
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));
}