Fix a minor bug in the dribble mode test
authorRohan Garg <rohangarg@kubuntu.org>
Wed, 19 Sep 2012 21:14:54 +0000 (02:44 +0530)
committerYouness Alaoui <youness.alaoui@collabora.co.uk>
Thu, 20 Sep 2012 18:05:54 +0000 (14:05 -0400)
If for some reason the opening of the socket is delayed, or simply takes
too much time, the test will fail. This patch ensures that the test will
only proceed once the socket is open.

tests/test-new-dribble.c

index adbe71d..9302455 100644 (file)
 #if !GLIB_CHECK_VERSION(2,31,8)
   static GMutex *stun_mutex_ptr = NULL;
   static GCond *stun_signal_ptr = NULL;
+  static GMutex *stun_thread_mutex_ptr = NULL;
+  static GCond *stun_thread_signal_ptr = NULL
 #else
   static GMutex stun_mutex;
   static GMutex *stun_mutex_ptr = &stun_mutex;
   static GCond stun_signal;
   static GCond *stun_signal_ptr = &stun_signal;
+  static GMutex stun_thread_mutex;
+  static GMutex *stun_thread_mutex_ptr = &stun_thread_mutex;
+  static GCond stun_thread_signal;
+  static GCond *stun_thread_signal_ptr = &stun_thread_signal;
 #endif
 
 static GMainLoop *global_mainloop;
@@ -214,6 +220,10 @@ static gpointer stun_thread_func (const gpointer user_data)
     g_assert_not_reached ();
   }
 
+  g_mutex_lock (stun_thread_mutex_ptr);
+  g_cond_signal (stun_thread_signal_ptr);
+  g_mutex_unlock (stun_thread_mutex_ptr);
+
   stun_agent_init (&oldagent, known_attributes,
       STUN_COMPATIBILITY_RFC3489, 0);
   stun_agent_init (&newagent, known_attributes,
@@ -654,6 +664,11 @@ int main(void)
                               stun_thread_func, NULL);
 #endif
 
+  // Once the the thread is forked, we want to listen for a signal 
+  // that the socket was opened successfully
+  g_mutex_lock (stun_thread_mutex_ptr);
+  g_cond_wait (stun_thread_signal_ptr, stun_thread_mutex_ptr); 
+
   lagent = nice_agent_new (g_main_loop_get_context (global_mainloop),
       NICE_COMPATIBILITY_RFC5245);
   ragent = nice_agent_new (g_main_loop_get_context (global_mainloop),