test_mutex.py 931 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from panda3d.core import Mutex, ReMutex
  2. def test_mutex_acquire_release():
  3. m = Mutex()
  4. m.acquire()
  5. # Assert that the lock is truly held now
  6. assert not m.try_acquire()
  7. # Release the lock
  8. m.release()
  9. # Make sure the lock is properly released
  10. assert m.try_acquire()
  11. # Clean up
  12. m.release()
  13. def test_mutex_try_acquire():
  14. m = Mutex()
  15. # Trying to acquire the lock should succeed
  16. assert m.try_acquire()
  17. # Assert that the lock is truly held now
  18. assert not m.try_acquire()
  19. # Clean up
  20. m.release()
  21. def test_remutex_acquire_release():
  22. m = ReMutex()
  23. m.acquire()
  24. m.acquire()
  25. m.release()
  26. m.release()
  27. def test_remutex_try_acquire():
  28. m = ReMutex()
  29. # Trying to acquire the lock should succeed
  30. assert m.try_acquire()
  31. # Trying a second time should succeed
  32. assert m.try_acquire()
  33. # Clean up
  34. m.release()
  35. m.release()