def test_locking_w_exception(self): """Make sure we release our lock if we've had an exception.""" key = decorators._get_lock_key('fake_func', self.pk) @decorators.lock_and_track def fake_func(import_file_pk): self.assertEqual(int(get_lock(key)), self.locked) raise TestException('Test exception!') self.assertRaises(TestException, fake_func, self.pk) # Even though execution failed part way through a call, we unlock. self.assertEqual(int(get_lock(key)), self.unlocked)
def test_locking_w_exception(self): """Make sure we release our lock if we've had an exception.""" key = decorators._get_lock_key('fake_func', self.pk) @decorators.lock_and_track def fake_func(import_file_pk): self.assertEqual(int(cache.get(key, 0)), self.locked) raise TestException('Test exception!') self.assertRaises(TestException, fake_func, self.pk) # Even though execution failed part way through a call, we unlock. self.assertEqual(int(cache.get(key, 0)), self.unlocked)
def test_locking(self): """Make sure we indicate we're locked if and only if we're inside the function.""" key = decorators._get_lock_key('fake_func', self.pk) self.assertEqual(int(get_lock(key)), self.unlocked) @decorators.lock_and_track def fake_func(import_file_pk): self.assertEqual(int(get_lock(key)), self.locked) fake_func(self.pk) self.assertEqual(int(get_lock(key)), self.unlocked)
def test_locking(self): """Make sure we indicate we're locked iff we're inside the function.""" key = decorators._get_lock_key('fake_func', self.pk) self.assertEqual(int(cache.get(key, 0)), self.unlocked) @decorators.lock_and_track def fake_func(import_file_pk): self.assertEqual(int(cache.get(key, 0)), self.locked) fake_func(self.pk) self.assertEqual(int(cache.get(key, 0)), self.unlocked)