From 7aafd22d0ef6c6ee84b09aaa6dc3beb1114baf4c Mon Sep 17 00:00:00 2001 From: Gabriel Braga Date: Tue, 9 Apr 2024 17:36:51 +0200 Subject: [PATCH] Fix unit tests to adapt to the epoll API 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. --- src/socket_handler.cpp | 5 +-- src/socket_server.cpp | 4 +- test/callback.cpp | 35 +++++++++++++++-------------- test/cmdgroup.cpp | 4 +- test/comm.cpp | 36 +++++++++++++++--------------- test/getsocket.cpp | 2 +- test/hello.cpp | 26 +++++++++++----------- test/newserver.cpp | 12 ++++------ test/reconnect.cpp | 28 ++++++++++++------------ test/reentrant.cpp | 22 ++++++++++++++----- test/serialize.cpp | 2 +- test/simplecmd.cpp | 8 +++--- test/test_fixtures.hxx | 1 - test/timeout.cpp | 32 ++++++++++++++-------------- test/wrapper.cpp | 55 +++++++++++++++++++++++------------------------ 15 files changed, 139 insertions(+), 133 deletions(-) diff --git a/src/socket_handler.cpp b/src/socket_handler.cpp index 355f623..5423b93 100644 --- a/src/socket_handler.cpp +++ b/src/socket_handler.cpp @@ -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"<(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); } diff --git a/test/cmdgroup.cpp b/test/cmdgroup.cpp index 942fd88..a58687e 100644 --- a/test/cmdgroup.cpp +++ b/test/cmdgroup.cpp @@ -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"; diff --git a/test/comm.cpp b/test/comm.cpp index 7b301a6..7f84241 100644 --- a/test/comm.cpp +++ b/test/comm.cpp @@ -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); diff --git a/test/getsocket.cpp b/test/getsocket.cpp index edd5eb3..5db3de8 100644 --- a/test/getsocket.cpp +++ b/test/getsocket.cpp @@ -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(...) { diff --git a/test/hello.cpp b/test/hello.cpp index 48ccf5c..dd653c4 100644 --- a/test/hello.cpp +++ b/test/hello.cpp @@ -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) diff --git a/test/newserver.cpp b/test/newserver.cpp index 5fa21b4..e03040c 100644 --- a/test/newserver.cpp +++ b/test/newserver.cpp @@ -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(...) { diff --git a/test/reconnect.cpp b/test/reconnect.cpp index bd4f60b..133a9e9 100644 --- a/test/reconnect.cpp +++ b/test/reconnect.cpp @@ -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 diff --git a/test/reentrant.cpp b/test/reentrant.cpp index c03e330..1d6547d 100644 --- a/test/reentrant.cpp +++ b/test/reentrant.cpp @@ -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 +#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; } diff --git a/test/serialize.cpp b/test/serialize.cpp index 8db3740..443c1c8 100644 --- a/test/serialize.cpp +++ b/test/serialize.cpp @@ -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"; diff --git a/test/simplecmd.cpp b/test/simplecmd.cpp index 97fa6da..e12014a 100644 --- a/test/simplecmd.cpp +++ b/test/simplecmd.cpp @@ -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(...) { diff --git a/test/test_fixtures.hxx b/test/test_fixtures.hxx index 255202e..10fcc23 100644 --- a/test/test_fixtures.hxx +++ b/test/test_fixtures.hxx @@ -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; diff --git a/test/timeout.cpp b/test/timeout.cpp index 1eb9e5b..a0b9ef2 100644 --- a/test/timeout.cpp +++ b/test/timeout.cpp @@ -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; diff --git a/test/wrapper.cpp b/test/wrapper.cpp index f7dcb88..90269d9 100644 --- a/test/wrapper.cpp +++ b/test/wrapper.cpp @@ -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(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(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(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(rc.get_result()); + if (!res) throw libt2n::t2n_communication_error("result object of wrong type"); + return res->get_data(); + } }; typedef T2nSingletonWrapper 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 (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 (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"; -- 1.7.1