def test_edit_successful(self): """Test that after a successful edit, the KtbsRoot semaphore exists and its value is 1.""" self.my_ktbs.label += '_test_edit_label' # Check that the semaphore has been created. with assert_raises(posix_ipc.ExistentialError): posix_ipc.Semaphore(name=get_semaphore_name(self.my_ktbs.uri), flags=posix_ipc.O_CREX) assert self.my_ktbs._get_semaphore().value == 1
def test_post_successful(self): """Test that after a successful post, the base semaphore exists and its value is 1.""" model = self.tmp_base.create_model() with assert_raises(posix_ipc.ExistentialError): posix_ipc.Semaphore(name=get_semaphore_name(self.tmp_base.uri), flags=posix_ipc.O_CREX) assert self.tmp_base._get_semaphore().value == 1 model.delete()
def test_post_successful(self): """Test that after a successful post, the KtbsRoot semaphore exists and its value is 1.""" base = self.my_ktbs.create_base() with assert_raises(posix_ipc.ExistentialError): posix_ipc.Semaphore(name=get_semaphore_name(self.my_ktbs.uri), flags=posix_ipc.O_CREX) assert self.my_ktbs._get_semaphore().value == 1 base.delete()
def test_edit_locked_root(self): """Test that a KtbsRoot.edit() fails if the root is already locked.""" semaphore = posix_ipc.Semaphore(name=get_semaphore_name(self.my_ktbs.uri), flags=posix_ipc.O_CREAT, initial_value=1) semaphore.acquire() assert semaphore.value == 0 with assert_raises(posix_ipc.BusyError): self.my_ktbs.label += '_test_edit_label' semaphore.release()
def test_lock_has_semaphore(self): """Test if KtbsRoot.lock() really acquires the semaphore.""" semaphore = posix_ipc.Semaphore(name=get_semaphore_name(self.my_ktbs.uri), flags=posix_ipc.O_CREAT, initial_value=1) assert semaphore.value == 1 with self.my_ktbs.lock(self.my_ktbs): assert self.my_ktbs._get_semaphore().value == 0 with assert_raises(posix_ipc.BusyError): semaphore.acquire(WithLockMixin.LOCK_DEFAULT_TIMEOUT)
def test_edit_successful(self): """Test that after a successful edit, the base semaphore exists and its value is 1.""" self.tmp_base.label += '_test_edit_label' # Check that the semaphore already exists, meaning that edit() used it. # If we don't check that, the semaphore value could still be 1 because we use _get_semaphore() # and initialize the semaphore value at 1. with assert_raises(posix_ipc.ExistentialError): posix_ipc.Semaphore(name=get_semaphore_name(self.tmp_base.uri), flags=posix_ipc.O_CREX) assert self.tmp_base._get_semaphore().value == 1
def test_lock_cant_get_semaphore(self): """Make sure KtbsRoot.lock() get stuck if the semaphore is already in use.""" semaphore = posix_ipc.Semaphore(name=get_semaphore_name(self.my_ktbs.uri), flags=posix_ipc.O_CREAT, initial_value=1) semaphore.acquire() assert semaphore.value == 0 with assert_raises(posix_ipc.BusyError): with self.my_ktbs.lock(self.my_ktbs): pass semaphore.release()
def test_edit_locked_base(self): """Test that a base.edit() fails if the base is already locked.""" semaphore = posix_ipc.Semaphore(name=get_semaphore_name(self.tmp_base.uri), flags=posix_ipc.O_CREAT, initial_value=1) semaphore.acquire() try: assert semaphore.value == 0 with assert_raises(posix_ipc.BusyError): self.tmp_base.label += '_test_edit_label' finally: semaphore.release()
def test_lock_cant_get_semaphore(self): """Make sure Base.lock() get stuck if the semaphore is already in use.""" semaphore = posix_ipc.Semaphore(name=get_semaphore_name(self.tmp_base.uri), flags=posix_ipc.O_CREAT, initial_value=1) semaphore.acquire() assert semaphore.value == 0 try: with assert_raises(posix_ipc.BusyError): with self.tmp_base.lock(self.tmp_base): pass finally: semaphore.release()
def test_delete_locked_base(self): """Tries to delete a base that is currently being locked.""" # Make a semaphore to lock the previously created base semaphore = posix_ipc.Semaphore(name=get_semaphore_name(self.tmp_base.uri), flags=posix_ipc.O_CREAT, initial_value=1) semaphore.acquire() assert semaphore.value == 0 # Tries to get a semaphore and delete a base, # it should block on the acquire() and raise a BusyError because a timeout is set. with assert_raises(posix_ipc.BusyError): self.tmp_base.delete() # Finally closing the semaphore we created for testing purpose. semaphore.release()
def test_delete_locked_base(self): """Tries to delete a base that is currently being locked.""" # Make a semaphore to lock the previously created base semaphore = posix_ipc.Semaphore(name=get_semaphore_name( self.tmp_base.uri), flags=posix_ipc.O_CREAT, initial_value=1) semaphore.acquire() assert semaphore.value == 0 # Tries to get a semaphore and delete a base, # it should block on the acquire() and raise a BusyError because a timeout is set. with assert_raises(posix_ipc.BusyError): self.tmp_base.delete() # Finally closing the semaphore we created for testing purpose. semaphore.release()