Francesco Romani has uploaded a new change for review.

Change subject: tests: sampling: add initial HostStatsThread tests
......................................................................

tests: sampling: add initial HostStatsThread tests

This patch adds a unit test to HostStatsThread.

Change-Id: Ic4e5765364cf46e1ebfaac72aa5f75c80e83779e
Relates-To: https://bugzilla.redhat.com/1113948
Signed-off-by: Francesco Romani <[email protected]>
---
M tests/samplingTests.py
M vdsm/virt/sampling.py
2 files changed, 37 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/29566/1

diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index 2ff703e..5126f69 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -21,6 +21,8 @@
 import os
 import tempfile
 import shutil
+import threading
+import time
 
 from vdsm import ipwrapper
 import virt.sampling as sampling
@@ -111,3 +113,37 @@
         s1 = sampling.InterfaceSample(lo)
         s1.operstate = 'x'
         self.assertEquals('operstate:x', s1.connlog_diff(s0))
+
+
+class HostStatsThread(TestCaseBase):
+    FAILED_SAMPLE = 3  # random 'small' value
+    STOP_SAMPLE = 6  # ditto
+
+    def setUp(self):
+        self._hs = None
+        self._sampleCount = 0
+        self._samplingDone = threading.Event()
+
+    def testContinueWithErrors(self):
+        """
+        bz1113948: do not give up on errors != TimeoutError
+        """
+        def WrapHostSample(pid):
+            self._sampleCount += 1
+            if self._sampleCount == self.FAILED_SAMPLE:
+                raise ValueError
+            if self._sampleCount == self.STOP_SAMPLE:
+                self._hs.stop()
+                self._samplingDone.set()
+            return None  # sampling.HostSample(pid)
+
+        def nosleep(seconds):
+            pass
+
+        with MonkeyPatchScope([(sampling, 'HostSample', WrapHostSample),
+                               (time, 'sleep', nosleep)]):
+            self._hs = sampling.HostStatsThread(self.log)
+            self._hs.start()
+            self._samplingDone.wait()
+            self._hs.stop()
+            self.assertTrue(self._sampleCount >= self.STOP_SAMPLE)
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 5f04f27..ccb0672 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -507,7 +507,7 @@
                                 exc_info=True)
             except Exception:
                 self._log.exception("Error while sampling stats")
-            self._stopEvent.wait(self.SAMPLE_INTERVAL_SEC)
+            time.sleep(self.SAMPLE_INTERVAL_SEC)
 
     @utils.memoized
     def _boot_time(self):


-- 
To view, visit http://gerrit.ovirt.org/29566
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic4e5765364cf46e1ebfaac72aa5f75c80e83779e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to