def test_MutexAutoLock_already_locked(self): Mutex.get_n_lock('dummy_lock') self.assertEqual(1, Mutex.objects.filter(id='dummy_lock').count()) with self.assertRaises(MutexLockedException): with MutexAutoLock('dummy_lock'): self.fail('cannot be here with lock enabled') self.assertEqual(1, Mutex.objects.filter(id='dummy_lock').count())
def test_mutex_autolock_already_locked(self): self.assertEqual(self.locked_func_legacy(12), 12) self.assertEqual(0, Mutex.objects.filter(id='dummy_lock').count()) Mutex.get_n_lock('dummy_lock') self.assertEqual(1, Mutex.objects.filter(id='dummy_lock').count()) with self.assertRaises(MutexLockedException): self.locked_func_legacy(5) self.assertEqual(1, Mutex.objects.filter(id='dummy_lock').count())
def test_MutexAutoLock_decorator_already_locked(self): self.assertEqual(self.locked_func(12), 12) self.assertEqual(0, Mutex.objects.filter(id='dummy_lock').count()) Mutex.get_n_lock('dummy_lock') self.assertEqual(1, Mutex.objects.filter(id='dummy_lock').count()) with self.assertRaises(MutexLockedException): self.locked_func(5) self.assertEqual(1, Mutex.objects.filter(id='dummy_lock').count())
def test_mutex_lock_twice_static_method(self): "Double lock causes an error (get_n_lock static method)" name = 'mutex-stuff' mutex = Mutex.get_n_lock(name) self.assertEqual(1, Mutex.objects.count()) with atomic(): self.assertRaises(MutexLockedException, Mutex.get_n_lock, name) mutex.release() self.assertEqual(0, Mutex.objects.count())