[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10711: allow test_threads() to time out (in tor/trunk: . src/or)



Author: nickm
Date: 2007-06-30 15:18:28 -0400 (Sat, 30 Jun 2007)
New Revision: 10711

Modified:
   tor/trunk/
   tor/trunk/src/or/test.c
Log:
 r13568@catbus:  nickm | 2007-06-30 15:18:18 -0400
 allow test_threads() to time out 



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r13568] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2007-06-30 18:06:00 UTC (rev 10710)
+++ tor/trunk/src/or/test.c	2007-06-30 19:18:28 UTC (rev 10711)
@@ -1403,7 +1403,8 @@
 test_threads(void)
 {
   char *s1, *s2;
-  int done = 0;
+  int done = 0, timedout = 0;
+  time_t started;
 #ifndef TOR_IS_MULTITHREADED
   /* Skip this test if we aren't threading. We should be threading most
    * everywhere by now. */
@@ -1422,16 +1423,26 @@
   spawn_func(_thread_test_func, s2);
   tor_mutex_release(_thread_test_start2);
   tor_mutex_release(_thread_test_start1);
+  started = time(NULL);
   while (!done) {
     tor_mutex_acquire(_thread_test_mutex);
     strmap_assert_ok(_thread_test_strmap);
     if (strmap_get(_thread_test_strmap, "thread 1") &&
-        strmap_get(_thread_test_strmap, "thread 2"))
+        strmap_get(_thread_test_strmap, "thread 2")) {
       done = 1;
+    } else if (time(NULL) > started + 10) {
+      timedout = done = 1;
+    }
     tor_mutex_release(_thread_test_mutex);
   }
   tor_mutex_free(_thread_test_mutex);
 
+  if (timedout) {
+    test_assert(strmap_get(_thread_test_strmap, "thread 1"));
+    test_assert(strmap_get(_thread_test_strmap, "thread 2"));
+    test_assert(!timedout);
+  }
+
   /* different thread IDs. */
   test_assert(strcmp(strmap_get(_thread_test_strmap, "thread 1"),
                      strmap_get(_thread_test_strmap, "thread 2")));