libt2n: (reinhard) fixed unit test.
[libt2n] / test / comm.cpp
index 5bba916..688cbf0 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdio.h>
+#include <time.h>
 
 #include <iostream>
 #include <string>
@@ -76,8 +77,10 @@ class test_comm : public TestFixture
             {
                 socket_server ss("./socket");
 
+                time_t t0 = time(NULL);
+
                 // max 10 sec
-                for (int i=0; i < 10; i++)
+                while (time(NULL) < t0 + 10 )
                 {
                     ss.fill_buffer(1000000);
 
@@ -106,8 +109,10 @@ class test_comm : public TestFixture
                 socket_server ss("./socket");
                 ss.set_logging(&cerr,debug);
 
+                time_t t0 = time(NULL);
+
                 // max 10 sec
-                for (int i=0; i < 10; i++)
+                while (time(NULL) < t0 + 10 )
                 {
                     ss.fill_buffer(1000000);
 
@@ -176,8 +181,10 @@ class test_comm : public TestFixture
                 socket_server ss("./socket");
                 ss.set_logging(&cerr,debug);
 
+                time_t t0 = time(NULL);
+
                 // max 10 sec
-                for (int i=0; i < 10; i++)
+                while (time(NULL) < t0 + 10 )
                 {
                     ss.fill_buffer(1000000);
 
@@ -194,6 +201,7 @@ class test_comm : public TestFixture
                         con->write(string().insert(0,100*1024,'y'));
                     }
                 }
+                std::cerr << "child: OVER" << std::endl;
                 // don't call atexit and stuff
                 _exit(0);
             }
@@ -247,8 +255,10 @@ class test_comm : public TestFixture
             {
                 socket_server ss(6666);
 
+                time_t t0 = time(NULL);
+
                 // max 10 sec
-                for (int i=0; i < 10; i++)
+                while (time(NULL) < t0 + 10 )
                 {
                     ss.fill_buffer(1000000);
 
@@ -277,8 +287,10 @@ class test_comm : public TestFixture
                 socket_server ss(6666);
                 ss.set_logging(&cerr,debug);
 
+                time_t t0 = time(NULL);
+
                 // max 10 sec
-                for (int i=0; i < 10; i++)
+                while (time(NULL) < t0 + 10 )
                 {
                     ss.fill_buffer(1000000);
 
@@ -347,8 +359,10 @@ class test_comm : public TestFixture
                 socket_server ss(6666);
                 ss.set_logging(&cerr,debug);
 
+                time_t t0 = time(NULL);
+
                 // max 10 sec
-                for (int i=0; i < 10; i++)
+                while (time(NULL) < t0 + 10 )
                 {
                     ss.fill_buffer(1000000);