libt2n: (gerd) fix client-connection-logic, finish wrappers, all tests are working...
[libt2n] / test / timeout.cpp
index 8bdfa31..6618ef6 100644 (file)
@@ -206,17 +206,9 @@ 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(true,sc.connection::is_closed());
             }
         }
     }
@@ -257,7 +249,7 @@ class test_timeout : public TestFixture
 
                 try
                 {
-                    command_client cc(sc,1000000,1000000);
+                    command_client cc(&sc,1000000,1000000);
                 }
                 catch(t2n_transfer_error &e)
                 { errormsg=e.what(); }
@@ -265,6 +257,8 @@ class test_timeout : public TestFixture
                 { throw; }
 
                 CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
+
+                kill(pid,SIGKILL);
             }
         }
     }
@@ -318,7 +312,7 @@ class test_timeout : public TestFixture
 
                 try
                 {
-                    command_client cc(sc,1000000,1000000);
+                    command_client cc(&sc,1000000,1000000);
                 }
                 catch(t2n_transfer_error &e)
                 { errormsg=e.what(); }
@@ -326,6 +320,8 @@ class test_timeout : public TestFixture
                 { throw; }
 
                 CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
+
+                kill(pid,SIGKILL);
             }
         }
     }
@@ -370,7 +366,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;
@@ -385,6 +381,8 @@ class test_timeout : public TestFixture
                 { throw; }
 
                 CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
+
+                kill(pid,SIGKILL);
             }
         }
     }
@@ -444,7 +442,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;
@@ -459,6 +457,8 @@ class test_timeout : public TestFixture
                 { throw; }
 
                 CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
+
+                kill(pid,SIGKILL);
             }
         }
     }
@@ -511,15 +511,17 @@ class test_timeout : public TestFixture
                 { throw; }
 
                 CPPUNIT_ASSERT_EQUAL(string("write() returned Broken pipe"),errormsg);
+
+                kill(pid,SIGKILL);
             }
         }
     }
 
     void DisconnectOnRead()
     {
-        pid_t pid;
+        pid_t pid1, pid2;
 
-        switch(pid=fork())
+        switch(pid1=fork())
         {
             case -1:
             {
@@ -563,7 +565,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 +605,15 @@ class test_timeout : public TestFixture
                 }
             }
         }
+        kill(pid1,SIGKILL);
+        kill(pid2,SIGKILL);
     }
 
     void BreakAccept()
     {
-        pid_t pid;
+        pid_t pid1,pid2;
 
-        switch(pid=fork())
+        switch(pid1=fork())
         {
             case -1:
             {
@@ -653,7 +657,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 +697,8 @@ class test_timeout : public TestFixture
                 }
             }
         }
+        kill(pid1,SIGKILL);
+        kill(pid2,SIGKILL);
     }
 };