示例#1
0
    def test_mutex_lock(self):
        mutex = Mutex(id='mutex-01')
        mutex.lock()

        self.get_object_or_fail(Mutex, pk=mutex.id)

        mutex.release()
        self.assertEqual(0, Mutex.objects.count())
示例#2
0
    def test_mutex_lock(self):
        mutex = Mutex(id='mutex-01')
        mutex.lock()

        self.get_object_or_fail(Mutex, pk=mutex.id)

        mutex.release()
        self.assertFalse(Mutex.objects.all())
示例#3
0
    def test_mutex_lock_twice_same_name(self):
        "Double lock causes an error (lock method)"
        name1 = 'mutex-01'
        name2 = 'other_mutex'

        mutex1 = Mutex(name1)
        mutex2 = Mutex(name1)

        mutex1.lock()

        with atomic():
            self.assertRaises(MutexLockedException, mutex2.lock)

        self.assertEqual(1, Mutex.objects.count())

        with self.assertNoException():
            mutex3 = Mutex(name2)
            mutex3.lock()

        self.assertEqual([name1, name2], self._get_ids())

        mutex1.release()
        self.assertEqual([name2], self._get_ids())