]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
tests: Fix qemumonitorjsontest deadlock when the machine is under load
authorPeter Krempa <pkrempa@redhat.com>
Mon, 12 Nov 2012 10:34:41 +0000 (11:34 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 13 Nov 2012 08:32:14 +0000 (09:32 +0100)
When doing the qemumonitorjsontest on a machine under heavy load the
test tends to deadlock from time to time. This patch adds the hack to
break the event loop that is used in virsh.

tests/qemumonitortestutils.c

index 93d2f6229bc2e7314082dc986c45f496973c83a2..7f7c855438679e81f52273d6b58cf7b4423d95e8 100644 (file)
@@ -331,9 +331,17 @@ static void qemuMonitorTestItemFree(qemuMonitorTestItemPtr item)
 }
 
 
+static void
+qemuMonitorTestFreeTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
+{
+    /* nothing to be done here */
+}
+
+
 void qemuMonitorTestFree(qemuMonitorTestPtr test)
 {
     size_t i;
+    int timer = -1;
 
     if (!test)
         return;
@@ -341,6 +349,8 @@ void qemuMonitorTestFree(qemuMonitorTestPtr test)
     virMutexLock(&test->lock);
     if (test->running) {
         test->quit = true;
+        /* HACK: Add a dummy timeout to break event loop */
+        timer = virEventAddTimeout(0, qemuMonitorTestFreeTimer, NULL, NULL);
     }
     virMutexUnlock(&test->lock);
 
@@ -361,6 +371,9 @@ void qemuMonitorTestFree(qemuMonitorTestPtr test)
     if (test->running)
         virThreadJoin(&test->thread);
 
+    if (timer != -1)
+        virEventRemoveTimeout(timer);
+
     for (i = 0 ; i < test->nitems ; i++)
         qemuMonitorTestItemFree(test->items[i]);
     VIR_FREE(test->items);