Fix unit tests to adapt to the epoll API
authorGabriel Braga <gabriel.braga@intra2net.com>
Tue, 9 Apr 2024 15:36:51 +0000 (17:36 +0200)
committerGabriel Braga <gabriel.braga@intra2net.com>
Fri, 26 Apr 2024 12:43:19 +0000 (14:43 +0200)
Previously the unit tests runs worked with the select API, after
changes to the epoll API the tests stopped running, this commit
fix and adapt them to the new API.

Note: This commit does some changes to timeouts and to some ports
on comm.cpp because the previous port was already in use by some
process on the developer's computer.

15 files changed:
src/socket_handler.cpp
src/socket_server.cpp
test/callback.cpp
test/cmdgroup.cpp
test/comm.cpp
test/getsocket.cpp
test/hello.cpp
test/newserver.cpp
test/reconnect.cpp
test/reentrant.cpp
test/serialize.cpp
test/simplecmd.cpp
test/test_fixtures.hxx
test/timeout.cpp
test/wrapper.cpp

index 355f623..5423b93 100644 (file)
@@ -339,7 +339,6 @@ void socket_handler::create_epoll()
     if (epoll_fd == -1)
         EXCEPTIONSTREAM(error,t2n_server_error, "error opening epoll: " << strerror(errno));
 
-    //adding sock (fd) to the set of events that epoll API will monitor
     if(sock != -1)
         add_to_epoll(sock,&sock);
     else
@@ -356,7 +355,7 @@ void socket_handler::add_to_epoll(int fd,void* ptr)
     struct epoll_event ev;
     ev.events = EPOLLIN;
     ev.data.ptr = ptr;
-    //adding newsock (client fd) to the set of events that epoll API will monitor
+
     if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd,&ev) == -1)
         EXCEPTIONSTREAM(error,t2n_server_error,"error adding server socket to epoll(): " << strerror(errno));
 
@@ -371,7 +370,7 @@ void socket_handler::add_to_epoll(int fd,void* ptr)
 void socket_handler::remove_from_epoll(int fd)
 {
     struct epoll_event ev;
-    //removing (client fd) from the set of events that epoll API monitors
+
     if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fd,&ev) == -1)
         LOGSTREAM(debug,"error deleting server socket to epoll(): " << strerror(errno) << "  ...ignoring"<<endl);
 }
index b8c4099..e80ee34 100644 (file)
@@ -131,7 +131,7 @@ socket_server::socket_server(const std::string& path, mode_t filemode, const std
             EXCEPTIONSTREAM(error,t2n_server_error,"error changing socket ownership: " << strerror(errno));
     }
 
-    socket_handler::create_epoll();
+    create_epoll();
 
     start_listening();
 
@@ -214,7 +214,7 @@ bool socket_server::fill_buffer(int timeout)
     {
         if (errno == EINTR)
         {
-            // select interrupted by signal
+            // epoll interrupted by signal
             nfds=0;
         }
         else
index eb600cb..0c39171 100644 (file)
@@ -87,7 +87,6 @@ BOOST_AUTO_TEST_CASE(ServerNewConnCallback)
             try
             {
                 string data;
-                // wait till server is up
                 sleep(1);
 
                 {
@@ -96,14 +95,15 @@ BOOST_AUTO_TEST_CASE(ServerNewConnCallback)
                     sc.write("ABC");
 
                     // wait half a sec
-                    sc.fill_buffer(500000);
+                    sc.fill_buffer(500);
                     sc.get_packet(data);
 
                     // close the connection
+
                 }
-            } catch(...)
+            } catch(std::exception &e)
             {
-                std::cerr << "exception in child. ignoring\n";
+                std::cerr << "exception in child. ignoring\n" << e.what();
             }
 
             // don't call atexit and stuff
@@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(ServerNewConnCallback)
             // max 3 sec
             for (int i=0; i < 3; i++)
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 string data;
                 unsigned int cid;
@@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(ServerConnClosedCallback)
                     sc.write("ABC");
 
                     // wait half a sec
-                    sc.fill_buffer(500000);
+                    sc.fill_buffer(500);
                     sc.get_packet(data);
 
                     // close the connection
@@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(ServerConnClosedCallback)
             // max 3 sec
             for (int i=0; i < 3; i++)
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 string data;
                 unsigned int cid;
@@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(ServerConnDeletedCallback)
                     sc.write("ABC");
 
                     // wait half a sec
-                    sc.fill_buffer(500000);
+                    sc.fill_buffer(500);
                     sc.get_packet(data);
 
                     // close the connection
@@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(ServerConnDeletedCallback)
             // max 3 sec
             for (int i=0; i < 3; i++)
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 string data;
                 unsigned int cid;
@@ -270,6 +270,7 @@ BOOST_AUTO_TEST_CASE(ServerConnDeletedCallback)
     }
 }
 
+
 BOOST_AUTO_TEST_CASE(ServerCallbackOrder)
 {
     switch(child_pid=fork())
@@ -294,7 +295,7 @@ BOOST_AUTO_TEST_CASE(ServerCallbackOrder)
                     sc.write("1");
 
                     // wait half a sec
-                    sc.fill_buffer(500000);
+                    sc.fill_buffer(500);
                     sc.get_packet(data);
 
                     sc.write("2");
@@ -322,7 +323,7 @@ BOOST_AUTO_TEST_CASE(ServerCallbackOrder)
 
             for (int i=0; i < 5; i++)
             {
-                ss.fill_buffer(500000);
+                ss.fill_buffer(1000);
 
                 string data;
                 unsigned int cid;
@@ -342,7 +343,7 @@ BOOST_AUTO_TEST_CASE(ServerCallbackOrder)
 
             for (int i=0; i < 4; i++)
             {
-                ss.fill_buffer(500000);
+                ss.fill_buffer(1000);
 
                 string data;
                 unsigned int cid;
@@ -376,7 +377,7 @@ BOOST_AUTO_TEST_CASE(ClientConnClosedCallback)
                 // max 3 sec
                 for (int i=0; i < 3; i++)
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -406,7 +407,7 @@ BOOST_AUTO_TEST_CASE(ClientConnClosedCallback)
             sc.write("ABC");
 
             // wait half a sec
-            sc.fill_buffer(500000);
+            sc.fill_buffer(500);
             sc.get_packet(data);
 
             BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
@@ -435,7 +436,7 @@ BOOST_AUTO_TEST_CASE(ClientConnDeletedCallback)
                 // max 3 sec
                 for (int i=0; i < 3; i++)
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(2000);
 
                     string data;
                     unsigned int cid;
@@ -465,8 +466,8 @@ BOOST_AUTO_TEST_CASE(ClientConnDeletedCallback)
 
                 sc.write("ABC");
 
-                // wait half a sec
-                sc.fill_buffer(500000);
+                // wait a sec
+                sc.fill_buffer(1000);
                 sc.get_packet(data);
             }
 
index 942fd88..a58687e 100644 (file)
@@ -195,7 +195,7 @@ BOOST_AUTO_TEST_CASE(GroupOk)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    cs.handle(1000000);
+                    cs.handle(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(WrongGroup)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    cs.handle(1000000);
+                    cs.handle(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
index 7b301a6..7f84241 100644 (file)
@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(UnixCommToServer)
             // max 10 sec
             while (time(NULL) < t0 + 10 )
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 if(ss.get_packet(data))
                     break;
@@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(UnixCommToServerAndBack)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -153,14 +153,14 @@ BOOST_AUTO_TEST_CASE(UnixCommToServerAndBack)
 
             sc.write("ABC");
 
-            sc.fill_buffer(1000000);
+            sc.fill_buffer(1000);
             sc.get_packet(data);
 
             BOOST_CHECK_EQUAL(string("DEF"),data);
 
             sc.write("HAHA");
 
-            sc.fill_buffer(1000000);
+            sc.fill_buffer(1000);
             sc.get_packet(data);
 
             BOOST_CHECK_EQUAL(string("xyz"),data);
@@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(UnixCommToServerAndBackBig)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(UnixCommToServerAndBackBig)
             sc.write(string().insert(0,100*1024,'x'));
 
             while (!sc.get_packet(data))
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             BOOST_CHECK_EQUAL(string().insert(0,100*1024,'y'),data);
 
@@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(IPCommToServer)
             {
                 // wait till server is up
                 sleep(1);
-                socket_client_connection sc(6666);
+                socket_client_connection sc(6665);
                 sc.write("hello");
             } catch(...)
             {
@@ -270,14 +270,14 @@ BOOST_AUTO_TEST_CASE(IPCommToServer)
         default:
         // parent
         {
-            socket_server ss(6666);
+            socket_server ss(6665);
 
             time_t t0 = time(NULL);
 
             // max 10 sec
             while (time(NULL) < t0 + 10 )
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 if(ss.get_packet(data))
                     break;
@@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(IPCommToServerAndBack)
         {
             try
             {
-                socket_server ss(6666);
+                socket_server ss(6665);
                 ss.set_logging(&cerr,debug);
 
                 time_t t0 = time(NULL);
@@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(IPCommToServerAndBack)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -342,17 +342,17 @@ BOOST_AUTO_TEST_CASE(IPCommToServerAndBack)
 
             // wait till server is up
             sleep(1);
-            socket_client_connection sc(6666);
+            socket_client_connection sc(6665);
             sc.write("ABC");
 
-            sc.fill_buffer(1000000);
+            sc.fill_buffer(1000);
             sc.get_packet(data);
 
             BOOST_CHECK_EQUAL(string("DEF"),data);
 
             sc.write("HAHA");
 
-            sc.fill_buffer(1000000);
+            sc.fill_buffer(1000);
             sc.get_packet(data);
 
             BOOST_CHECK_EQUAL(string("xyz"),data);
@@ -377,7 +377,7 @@ BOOST_AUTO_TEST_CASE(IPCommToServerAndBackBig)
         {
             try
             {
-                socket_server ss(6666);
+                socket_server ss(6665);
                 ss.set_logging(&cerr,debug);
 
                 time_t t0 = time(NULL);
@@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(IPCommToServerAndBackBig)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -418,12 +418,12 @@ BOOST_AUTO_TEST_CASE(IPCommToServerAndBackBig)
 
             // wait till server is up
             sleep(1);
-            socket_client_connection sc(6666);
+            socket_client_connection sc(6665);
 
             sc.write(string().insert(0,100*1024,'x'));
 
             while (!sc.get_packet(data))
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             BOOST_CHECK_EQUAL(string().insert(0,2048*1024,'y'),data);
 
index edd5eb3..5db3de8 100644 (file)
@@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(SocketCheck)
                 for (int i=0; i < 10; i++)
                 {
                     SocketSet = ss.get_sockets_set();
-                    cs.handle(1000000);
+                    cs.handle(1000);
                 }
             } catch(...)
             {
index 48ccf5c..dd653c4 100644 (file)
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(HelloOk)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(BadTag)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(BadTag)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(BadVersion)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(BadVersion)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(SeparatorMissing)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -263,7 +263,7 @@ BOOST_AUTO_TEST_CASE(SeparatorMissing)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(WrongByteOrder)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(WrongByteOrder)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE(OtherServerBig)
 
                 // max 3 sec
                 for (int i=0; i < 3; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(OtherServerBig)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE(OtherServerSmall)
 
                 // max 3 sec
                 for (int i=0; i < 3; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -442,7 +442,7 @@ BOOST_AUTO_TEST_CASE(OtherServerSmall)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
index 5fa21b4..e03040c 100644 (file)
@@ -123,6 +123,7 @@ BOOST_FIXTURE_TEST_SUITE(test_newserver, KillChildOnShutdownFixture)
 
 BOOST_AUTO_TEST_CASE(NewServerSocket)
 {
+
     switch(child_pid=fork())
     {
         case -1:
@@ -139,23 +140,20 @@ BOOST_AUTO_TEST_CASE(NewServerSocket)
                     socket_server ss("./socket");
                     // ss.set_logging(&cerr,debug);
                     command_server cs(ss);
-
                     // handle new connection and just one command
-                    cs.handle(10000000);
-                    cs.handle(10000000);
+                    cs.handle(10000);
+                    cs.handle(10000);
                 }
 
-                sleep(1);
+                sleep(2);
 
                 // close socket, create new one
                 {
                     socket_server ss("./socket");
-                    // ss.set_logging(&cerr,debug);
                     command_server cs(ss);
-
                     // max 30 sec
                     for (int i=0; i < 30; i++)
-                        cs.handle(1000000);
+                        cs.handle(1000);
                 }
             } catch(...)
             {
index bd4f60b..133a9e9 100644 (file)
@@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(simple_reconnect)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -109,14 +109,14 @@ BOOST_AUTO_TEST_CASE(simple_reconnect)
             string data;
 
             while (!sc.get_packet(data))
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             sc.reconnect();
 
             sc.write("x");
 
             while (!sc.get_packet(data))
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             BOOST_CHECK_EQUAL(string().insert(0,100,'X'),data);
         }
@@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(reconnect_with_close)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -186,7 +186,7 @@ BOOST_AUTO_TEST_CASE(reconnect_with_close)
             string data;
 
             while (!sc.get_packet(data))
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             sc.close();
 
@@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(reconnect_with_close)
             sc.write("x");
 
             while (!sc.get_packet(data))
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             BOOST_CHECK_EQUAL(string().insert(0,100,'X'),data);
         }
@@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_complete)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_complete)
             string data;
 
             while (!sc.packet_available())
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             sc.reconnect();
 
@@ -300,7 +300,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_several_complete)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -345,7 +345,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_several_complete)
 
             // max 3 sec
             while (time(NULL) < t0 + 3 )
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             // we now should have packets complete packets in the buffer
 
@@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_no_incomplete1)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_no_incomplete1)
 
             // max 3 sec
             while (time(NULL) < t0 + 3 )
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             // we now should have one complete packet and some stuff in the buffer
 
@@ -474,7 +474,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_no_incomplete2)
                 // max 10 sec
                 while (time(NULL) < t0 + 10 )
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -530,7 +530,7 @@ BOOST_AUTO_TEST_CASE(reconnect_buffer_no_incomplete2)
 
             // max 3 sec
             while (time(NULL) < t0 + 3 )
-                sc.fill_buffer(1000000);
+                sc.fill_buffer(1000);
 
             // we now should have one complete packet and some stuff in the buffer
 
index c03e330..1d6547d 100644 (file)
@@ -66,7 +66,7 @@ string testfunc(const string& str)
 
     // call handle, eventually reentrant
     if (global_server)
-        global_server->handle(10000);
+        global_server->handle(1);
 
     ++seen_client_requests;
 
@@ -136,6 +136,7 @@ class testfunc_cmd : public libt2n::command
 
 
 #include <boost/serialization/export.hpp>
+#include "monotonic_clock.hxx"
 
 BOOST_CLASS_EXPORT(reentrant::testfunc_cmd)
 BOOST_CLASS_EXPORT(reentrant::testfunc_res)
@@ -157,7 +158,7 @@ BOOST_AUTO_TEST_CASE(ReentrantServer)
         // child
         {
             // wait till server is up
-            sleep(2);
+            sleep(1);
 
             // hammer the server
             for (int i = 0; i < fork_count; i++)
@@ -168,7 +169,6 @@ BOOST_AUTO_TEST_CASE(ReentrantServer)
                 for (int i=0; i < requests_per_child; i++)
                 {
                     socket_client_connection sc("./socket");
-                    // sc.set_logging(&cerr,debug);
                     command_client cc(&sc);
 
                     result_container rc;
@@ -214,16 +214,26 @@ BOOST_AUTO_TEST_CASE(ReentrantServer)
             while (seen_client_requests < all_requests)
             {
                 ++safety_check;
+
                 if (safety_check > 10) {
                     std::cerr << "reached safety check, aborting.\n";
                     break;
                 }
 
-                long long maxtime=1000000;
+                int maxtime=1000;
+                int millisec_checkpoit;
+
                 while(maxtime > 0)
-                    cs.handle(maxtime);
+                {
+                    millisec_checkpoit = monotonic_clock_gettime_msec();
+                    if (millisec_checkpoit != -1)
+                    {
+                        cs.handle(maxtime);
+                        maxtime -= abs(monotonic_clock_gettime_msec() - millisec_checkpoit);
+                    }
+                    else _exit(1);
+                }
             }
-
             global_server = NULL;
         }
 
index 8db3740..443c1c8 100644 (file)
@@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(ClientSerializeErr)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    cs.handle(1000000);
+                    cs.handle(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
index 97fa6da..e12014a 100644 (file)
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(SimpleCmd)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    cs.handle(1000000);
+                    cs.handle(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(SimpleException)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    cs.handle(1000000);
+                    cs.handle(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(BigReturn)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    cs.handle(1000000);
+                    cs.handle(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(BigParameter)
 
                 // max 60 sec - we need atleast 28 handle calls to transfer the buffer
                 for (int i=0; i < 60; i++) {
-                    cs.handle(1000000);
+                    cs.handle(1000);
             }
             } catch(...)
             {
index 255202e..10fcc23 100644 (file)
@@ -74,7 +74,6 @@ public:
         // make sure the server-child is dead before the next test runs
         if (child_pid)
         {
-            // std::cout << "Killing child with pid: " << child_pid << std::endl;
             kill(child_pid, SIGKILL);
 
             int status = 0;
index 1eb9e5b..a0b9ef2 100644 (file)
@@ -145,13 +145,13 @@ protected:
         // this is an evil hack to get access to real_write, don't ever do this in an app!!!
         real_write_connection *rwc=(real_write_connection*)ssc;
 
-        // we write one char each 0.2 sec
+        // we write one char each 0.5 sec
         for (int pos=0; pos < data.size(); pos++)
         {
             string onebyte;
             onebyte+=data[pos];
             rwc->real_write(onebyte);
-            usleep(200000);
+            usleep(500000);
         }
     }
 };
@@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(HelloTimeoutNothing)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -237,9 +237,9 @@ BOOST_AUTO_TEST_CASE(HelloTimeoutNothing)
             // wait till server is up
             sleep(1);
             socket_client_connection sc("./socket");
-            command_client cc(&sc,1000000,1000000);
+            command_client cc(&sc,1,1);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -281,7 +281,7 @@ BOOST_AUTO_TEST_CASE(HelloTimeoutSlowData)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -299,9 +299,9 @@ BOOST_AUTO_TEST_CASE(HelloTimeoutSlowData)
             // wait till server is up
             sleep(1);
             socket_client_connection sc("./socket");
-            command_client cc(&sc,1000000,1000000);
+            command_client cc(&sc,100,100);
 
-            t2n_exception* ep=cc.get_constructor_exception();
+            t2n_exception* ep= cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE(CommandTimeout)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";
@@ -357,7 +357,7 @@ BOOST_AUTO_TEST_CASE(CommandTimeout)
             sleep(1);
             socket_client_connection sc("./socket");
 
-            command_client cc(&sc,1000000,1000000);
+            command_client cc(&sc,1,1);
             result_container rc;
 
             string errormsg;
@@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(CommandSlowResponse)
                 // max 10 sec
                 for (int i=0; i < 10; i++)
                 {
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
 
                     string data;
                     unsigned int cid;
@@ -434,7 +434,7 @@ BOOST_AUTO_TEST_CASE(CommandSlowResponse)
             sleep(1);
             socket_client_connection sc("./socket");
 
-            command_client cc(&sc,1000000,1000000);
+            command_client cc(&sc,10,10);
             result_container rc;
 
             string errormsg;
@@ -613,7 +613,7 @@ BOOST_AUTO_TEST_CASE(DisconnectOnRead)
             // max 5 sec
             while (time(NULL) < t0 + 5 )
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 string data;
                 ss.get_packet(data);
@@ -656,7 +656,7 @@ BOOST_AUTO_TEST_CASE(DisconnectOnRead)
                     // max 10 sec
                     while (time(NULL) < t0 + 10 )
                     {
-                        ss.fill_buffer(1000000);
+                        ss.fill_buffer(1000);
 
                         if (ss.get_packet(received))
                             break;
@@ -716,7 +716,7 @@ BOOST_AUTO_TEST_CASE(BreakAccept)
             // max 5 sec
             while (time(NULL) < t0 + 5 )
             {
-                ss.fill_buffer(1000000);
+                ss.fill_buffer(1000);
 
                 string data;
                 ss.get_packet(data);
@@ -759,7 +759,7 @@ BOOST_AUTO_TEST_CASE(BreakAccept)
                     // max 10 sec
                     while (time(NULL) < t0 + 10 )
                     {
-                        ss.fill_buffer(1000000);
+                        ss.fill_buffer(1000);
 
                         if (ss.get_packet(received))
                             break;
index f7dcb88..90269d9 100644 (file)
@@ -202,30 +202,30 @@ class cmd_group_x_client : public command_client
 {
     public:
         cmd_group_x_client(libt2n::client_connection *_c,
-         long long _command_timeout_usec=command_timeout_millisec_default,
-         long long _hello_timeout_usec=hello_timeout_millisec_default)
-         : libt2n::command_client(_c,_command_timeout_usec,_hello_timeout_usec)
+         int _command_timeout_sec=command_timeout_millisec_default,
+         int _hello_timeout_sec=hello_timeout_millisec_default)
+         : libt2n::command_client(_c,_command_timeout_sec,_hello_timeout_sec)
         {}
 
-    int serverfunc(int i)
-    {
-        libt2n::result_container rc;
+        int serverfunc(int i)
+        {
+            libt2n::result_container rc;
 
-        send_command(new serverfunc_cmd(i), rc);
-        serverfunc_res* res=dynamic_cast<serverfunc_res*>(rc.get_result());
-        if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
-        return res->get_data();
-    }
+            send_command(new serverfunc_cmd(i), rc);
+            serverfunc_res* res=dynamic_cast<serverfunc_res*>(rc.get_result());
+            if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
+            return res->get_data();
+        }
 
-    std::string getserverlog(void)
-    {
-        libt2n::result_container rc;
+        std::string getserverlog(void)
+        {
+            libt2n::result_container rc;
 
-        send_command(new getserverlog_cmd(), rc);
-        getserverlog_res* res=dynamic_cast<getserverlog_res*>(rc.get_result());
-        if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
-        return res->get_data();
-    }
+            send_command(new getserverlog_cmd(), rc);
+            getserverlog_res* res=dynamic_cast<getserverlog_res*>(rc.get_result());
+            if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
+            return res->get_data();
+        }
 };
 
 typedef T2nSingletonWrapper<cmd_group_x_client> wraptype;
@@ -268,7 +268,7 @@ public:
 
                         // max 10 sec
                         for (; !close_server && !kill_server && i < 10; i++)
-                            cs.handle(1000000);
+                            cs.handle(1000);
                     }
                 } catch(...)
                 {
@@ -358,14 +358,13 @@ BOOST_AUTO_TEST_CASE(reconnect_after_close)
     wraptype::set_connection(auto_ptr<ConnectionWrapper>
         (new ReconnectSocketWrapper("./socket")));
 
-    wraptype::get_connection_wrapper()->set_command_timeout_millisec(3000000);
-    wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3000000);
+    wraptype::get_connection_wrapper()->set_command_timeout_millisec(200);
+    wraptype::get_connection_wrapper()->set_hello_timeout_millisec(200);
 
     // 42 closes connection on the server side
     t2n_exec(&cmd_group_x_client::serverfunc)(42);
 
     string out=t2n_exec(&cmd_group_x_client::getserverlog)();
-
     // count the number of times that "new connection accepted" appears in the server log
     string::size_type p=0;
     int cnt=0;
@@ -406,8 +405,8 @@ BOOST_AUTO_TEST_CASE(ignore_handler_reconnects)
     wraptype::set_connection(auto_ptr<ConnectionWrapper>
         (new ReconnectIgnoreFailureSocketWrapper("./socket")));
 
-    wraptype::get_connection_wrapper()->set_command_timeout_millisec(3000000);
-    wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3000000);
+    wraptype::get_connection_wrapper()->set_command_timeout_millisec(3);
+    wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3);
 
     // 42 closes connection on the server side
     t2n_exec(&cmd_group_x_client::serverfunc)(42);
@@ -478,7 +477,7 @@ BOOST_AUTO_TEST_CASE(ignore_finds_lateserver)
 
                     // max 10 sec
                     for (; !close_server && !kill_server && i < 10; i++)
-                        cs.handle(1000000);
+                        cs.handle(1000);
                 }
             } catch(...)
             {
@@ -493,7 +492,7 @@ BOOST_AUTO_TEST_CASE(ignore_finds_lateserver)
         // parent
         {
             // wait till server is up
-            sleep(2);
+            sleep(1);
         }
     }
 
@@ -533,7 +532,7 @@ BOOST_AUTO_TEST_CASE(ignore_wrongserver)
 
                 // max 10 sec
                 for (int i=0; i < 10; i++)
-                    ss.fill_buffer(1000000);
+                    ss.fill_buffer(1000);
             } catch(...)
             {
                 std::cerr << "exception in child. ignoring\n";