예제 #1
0
        def failing_task():
            tasks.acquire_lock("dummylock", 3600)

            try:
                models.Video.objects.create(public_id="id")
                models.Video.objects.create(public_id="id")
            finally:
                tasks.release_lock("dummylock")
예제 #2
0
    def test_context_manager(self):

        # 1) Lock is available
        with tasks.Lock("dummylock") as lock:
            self.assertTrue(lock.is_acquired)
            self.assertRaises(exceptions.LockUnavailable, tasks.acquire_lock,
                              "dummylock")

        self.assertFalse(lock.is_acquired)

        # 2) Lock is unavailable
        tasks.acquire_lock("dummylock")
        with tasks.Lock("dummylock") as lock:
            self.assertFalse(lock.is_acquired)

        self.assertRaises(exceptions.LockUnavailable, tasks.acquire_lock,
                          "dummylock")
예제 #3
0
    def test_release_lock_with_integrity_error(self):
        def failing_task():
            tasks.acquire_lock("dummylock", 3600)

            try:
                models.Video.objects.create(public_id="id")
                models.Video.objects.create(public_id="id")
            finally:
                tasks.release_lock("dummylock")

        self.assertRaises(IntegrityError, failing_task)
        self.assertTrue(tasks.acquire_lock("dummylock"))
예제 #4
0
 def test_acquire_release_lock_cycle(self):
     self.assertTrue(tasks.acquire_lock("dummylock"))
     self.assertRaises(exceptions.LockUnavailable, tasks.acquire_lock,
                       "dummylock")
     tasks.release_lock("dummylock")
     self.assertTrue(tasks.acquire_lock("dummylock"))