mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
tests: add some simple smoke tests for Mutex and ReMutex
This commit is contained in:
parent
cf4f8b35b6
commit
171ba35f26
54
tests/pipeline/test_mutex.py
Normal file
54
tests/pipeline/test_mutex.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
from panda3d.core import Mutex, ReMutex
|
||||||
|
|
||||||
|
|
||||||
|
def test_mutex_acquire_release():
|
||||||
|
m = Mutex()
|
||||||
|
m.acquire()
|
||||||
|
|
||||||
|
# Assert that the lock is truly held now
|
||||||
|
assert not m.try_acquire()
|
||||||
|
|
||||||
|
# Release the lock
|
||||||
|
m.release()
|
||||||
|
|
||||||
|
# Make sure the lock is properly released
|
||||||
|
assert m.try_acquire()
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
m.release()
|
||||||
|
|
||||||
|
|
||||||
|
def test_mutex_try_acquire():
|
||||||
|
m = Mutex()
|
||||||
|
|
||||||
|
# Trying to acquire the lock should succeed
|
||||||
|
assert m.try_acquire()
|
||||||
|
|
||||||
|
# Assert that the lock is truly held now
|
||||||
|
assert not m.try_acquire()
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
m.release()
|
||||||
|
|
||||||
|
|
||||||
|
def test_remutex_acquire_release():
|
||||||
|
m = ReMutex()
|
||||||
|
m.acquire()
|
||||||
|
m.acquire()
|
||||||
|
m.release()
|
||||||
|
m.release()
|
||||||
|
|
||||||
|
|
||||||
|
def test_remutex_try_acquire():
|
||||||
|
m = ReMutex()
|
||||||
|
|
||||||
|
# Trying to acquire the lock should succeed
|
||||||
|
assert m.try_acquire()
|
||||||
|
|
||||||
|
# Trying a second time should succeed
|
||||||
|
assert m.try_acquire()
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
m.release()
|
||||||
|
m.release()
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user