X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Ftimeout.cpp;h=7a4e9ed7c9a4d58f5f087aacefb12029c43d0e80;hp=8bdfa31fd1e55419551d634b376a49569571b108;hb=e72e07f3178ced4277066c5df4dfd5934fac49e8;hpb=c7857475c8b0f02cac3ce29a617a4d542fa59f37 diff --git a/test/timeout.cpp b/test/timeout.cpp index 8bdfa31..7a4e9ed 100644 --- a/test/timeout.cpp +++ b/test/timeout.cpp @@ -143,6 +143,8 @@ class test_timeout : public TestFixture CPPUNIT_TEST_SUITE_END(); + pid_t child_pid; + public: typedef uint32_t packet_size_indicator; @@ -151,7 +153,11 @@ class test_timeout : public TestFixture { } void tearDown() - { } + { + // make sure the server-child is dead before the next test runs + kill(child_pid,SIGKILL); + sleep(1); + } void send_hello(string hello_string, socket_server* ss, unsigned int conn_id) { @@ -178,9 +184,7 @@ class test_timeout : public TestFixture void ConnectTimeout() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -206,26 +210,18 @@ class test_timeout : public TestFixture string errormsg; - try - { - socket_client_connection sc("./socket"); - command_client cc(sc,1000000,1000000); - } - catch(t2n_transfer_error &e) - { errormsg=e.what(); } - catch(...) - { throw; } + socket_client_connection sc("./socket"); - CPPUNIT_ASSERT_EQUAL(string("error reading from socket : Invalid argument"),errormsg); + CPPUNIT_ASSERT_EQUAL_MESSAGE("connection not closed",true,sc.connection::is_closed()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong errormessage",string("no more retries left after connect error"),sc.get_last_error_msg()); } } } void HelloTimeoutNothing() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -252,17 +248,13 @@ class test_timeout : public TestFixture // wait till server is up sleep(1); socket_client_connection sc("./socket"); + command_client cc(&sc,1000000,1000000); - string errormsg; + t2n_exception* ep=cc.get_constuctor_exception(); - try - { - command_client cc(sc,1000000,1000000); - } - catch(t2n_transfer_error &e) - { errormsg=e.what(); } - catch(...) - { throw; } + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg); } @@ -271,9 +263,7 @@ class test_timeout : public TestFixture void HelloTimeoutSlowData() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -313,17 +303,13 @@ class test_timeout : public TestFixture // wait till server is up sleep(1); socket_client_connection sc("./socket"); + command_client cc(&sc,1000000,1000000); - string errormsg; + t2n_exception* ep=cc.get_constuctor_exception(); - try - { - command_client cc(sc,1000000,1000000); - } - catch(t2n_transfer_error &e) - { errormsg=e.what(); } - catch(...) - { throw; } + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg); } @@ -332,9 +318,7 @@ class test_timeout : public TestFixture void CommandTimeout() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -370,7 +354,7 @@ class test_timeout : public TestFixture sleep(1); socket_client_connection sc("./socket"); - command_client cc(sc,1000000,1000000); + command_client cc(&sc,1000000,1000000); result_container rc; string errormsg; @@ -391,9 +375,7 @@ class test_timeout : public TestFixture void CommandSlowResponse() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -444,7 +426,7 @@ class test_timeout : public TestFixture sleep(1); socket_client_connection sc("./socket"); - command_client cc(sc,1000000,1000000); + command_client cc(&sc,1000000,1000000); result_container rc; string errormsg; @@ -465,9 +447,7 @@ class test_timeout : public TestFixture void DisconnectOnWrite() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -499,7 +479,7 @@ class test_timeout : public TestFixture string errormsg; - string huge(1000000,'x'); + string huge(5000000,'x'); try { @@ -517,9 +497,9 @@ class test_timeout : public TestFixture void DisconnectOnRead() { - pid_t pid; + pid_t pid2; - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -563,7 +543,7 @@ class test_timeout : public TestFixture // are we still alive and able to process data? - switch(pid=fork()) + switch(pid2=fork()) { case -1: { @@ -603,13 +583,14 @@ class test_timeout : public TestFixture } } } + kill(pid2,SIGKILL); } void BreakAccept() { - pid_t pid; + pid_t pid2; - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -653,7 +634,7 @@ class test_timeout : public TestFixture // are we still alive and able to process data? - switch(pid=fork()) + switch(pid2=fork()) { case -1: { @@ -693,6 +674,7 @@ class test_timeout : public TestFixture } } } + kill(pid2,SIGKILL); } };