def test_obtain_release_lock(self):
    if not CONFIG.is_pg:
      return
    da0 = get_data_access().open()
    da1 = get_data_access().open()

    key = 1

    # Get lock with first connection
    self.assertTrue(obtain_lock(da0, key, LockMode.skip))

    # Try to get lock with second connection, fails
    self.assertFalse(obtain_lock(da1, key, LockMode.skip))

    # Try to release lock with second connection, fails
    self.assertFalse(release_lock(da1, key))

    # Release lock wth first connection
    self.assertTrue(release_lock(da0, key))

    # Get lock with second connection
    self.assertTrue(obtain_lock(da1, key, LockMode.skip))

    # Release lock with second connection
    self.assertTrue(release_lock(da1, key))
Exemple #2
0
 def _get_next_job(self):
   """Returns a 2-tuple of (job, serialization_key) for the highest priority
   waiting job that has an open serialization key. Returns (None, None) if
   no such job exists.
   """
   if not self._cooperative:
     return self._get_next_job_inner()
   else:
     if self._cooperative.mode == Cooperative.none:
       return self._get_next_job_inner()
     elif self._cooperative.mode == Cooperative.advisory_lock:
       adv.obtain_lock(self._model_access, self._cooperative.args, xact=True)
       return self._get_next_job_inner()
     elif self._cooperative.mode == Cooperative.row_lock:
       return self._get_next_job_inner(row_lock=True)