Dan Kenigsberg has submitted this change and it was merged.
Change subject: tests: Introduce AssertingLock
......................................................................
tests: Introduce AssertingLock
When we want to test locking, we don't want to poke into object
internals and check the state of objects locks, or even worse, mock out
object lock.
This patch introduces the AssertingLock, which unlike regular locks,
never blocks when you try to acquire a lock somebody else is holding.
Instead, this lock raises AssertionError, failing the test.
Assuming that Foo object implements the context manager and use a lock,
we can verify this by:
single_thread = AssertingLock()
foo = Foo()
def check():
with foo:
with single_thread:
time.sleep(0.1)
Now we can run check in several threads; if foo is implemented
correctly, single thread will be able to enter the foo context. If foo
does not lock properly, multiple thread will enter this context, and
then fail when trying to enter the AssertingLock.
Turns out that in the SamplingMethodTests, I used a BoundedSemaphore for
this purpuse which is incorrect. Incorrect code can be hidden becuase
the testing threads would block instead of failing the tests. This code
uses now an AssertingLock instead.
Change-Id: I3e3aad4015e3410ce2f2b39bba84314cce5580b6
Signed-off-by: Nir Soffer <[email protected]>
Reviewed-on: http://gerrit.ovirt.org/30938
Reviewed-by: Federico Simoncelli <[email protected]>
---
M tests/miscTests.py
M tests/testlib.py
M tests/testlibTests.py
3 files changed, 35 insertions(+), 1 deletion(-)
Approvals:
Nir Soffer: Verified
Federico Simoncelli: Looks good to me, approved
--
To view, visit http://gerrit.ovirt.org/30938
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3e3aad4015e3410ce2f2b39bba84314cce5580b6
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <[email protected]>
Gerrit-Reviewer: Allon Mureinik <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
Gerrit-Reviewer: Federico Simoncelli <[email protected]>
Gerrit-Reviewer: Francesco Romani <[email protected]>
Gerrit-Reviewer: Nir Soffer <[email protected]>
Gerrit-Reviewer: Yoav Kleinberger <[email protected]>
Gerrit-Reviewer: [email protected]
Gerrit-Reviewer: oVirt Jenkins CI Server
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches