Change in vdsm[master]: tests: Fix rare deadlock in profile threads tests
nsoffer at redhat.com
nsoffer at redhat.com
Wed Aug 13 14:57:18 UTC 2014
Nir Soffer has uploaded a new change for review.
Change subject: tests: Fix rare deadlock in profile threads tests
......................................................................
tests: Fix rare deadlock in profile threads tests
There was a race in the test for profiling running threads, where the
thread was joined too quickly, while the thread was starting. Seems that
there is a deadlock in Python 2.7 when using pthreading. I did not try
this on Python 2.6 or Python 2.7 without pthreading. This caused the
ThreadsProfileTests.test_running_threads to fail onece in a while.
Now the tests use more robust setup to ensure that we join a thread only
after it was started. There are two events: ready and resume. The
worker thread set ready, and wait on resume. The test wait on ready and
set resume.
I verified this change by running the failing tests 1000 times in a
loop, without any failure. Before this, we could not get 100 successful
runs.
The deadlock should be handled separately. This may be a pthreding or
Python bug.
Change-Id: I03594842ca341a7a2d54542396ef8ce82a67e167
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/profileTests.py
1 file changed, 5 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/70/31470/1
diff --git a/tests/profileTests.py b/tests/profileTests.py
index ac217e4..4e9ff7c 100644
--- a/tests/profileTests.py
+++ b/tests/profileTests.py
@@ -266,6 +266,7 @@
def setUp(self):
self.thread = None
self.ready = threading.Event()
+ self.resume = threading.Event()
@MonkeyPatch(profile, 'config', make_config(enable='false'))
def test_new_threads(self):
@@ -299,30 +300,30 @@
@profile.profile(FILENAME, format="ystat", threads=True)
def new_threads(self):
self.start_thread()
- self.ready.set()
self.join_thread()
@profile.profile(FILENAME, format="ystat", threads=True)
def running_threads(self):
- self.ready.set()
self.join_thread()
@profile.profile(FILENAME, format="ystat", threads=False)
def without_threads(self):
self.start_thread()
- self.ready.set()
self.join_thread()
def start_thread(self):
self.thread = threading.Thread(target=self.worker)
self.thread.daemon = True
self.thread.start()
+ self.ready.wait()
def join_thread(self):
+ self.resume.set()
self.thread.join()
def worker(self):
- self.ready.wait()
+ self.ready.set()
+ self.resume.wait()
self.worker_function()
def worker_function(self):
--
To view, visit http://gerrit.ovirt.org/31470
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I03594842ca341a7a2d54542396ef8ce82a67e167
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>
More information about the vdsm-patches
mailing list