Esempio n. 1
0
    def test_retry(self, sleep):
        def raise_lock_and_open_failure(file_name):
            if random.randint(0, 1) > 0:
                raise AcquireLockFailure()
            else:
                raise InvalidFile()

        file_io = _FileLock(DatastoreType.EXT3)
        file_io._lock_and_open = MagicMock()
        file_io._lock_and_open.side_effect = raise_lock_and_open_failure

        try:
            file_io.lock_and_open(self.tempfile, retry=100, wait=0.1)
        except AcquireLockFailure:
            pass
        except InvalidFile:
            pass
        assert_that(file_io._lock_and_open.call_count, equal_to(101))
Esempio n. 2
0
    def test_retry(self, sleep):
        def raise_lock_and_open_failure(file_name):
            if random.randint(0, 1) > 0:
                raise AcquireLockFailure()
            else:
                raise InvalidFile()

        file_io = _FileLock(DatastoreType.EXT3)
        file_io._lock_and_open = MagicMock()
        file_io._lock_and_open.side_effect = raise_lock_and_open_failure

        try:
            file_io.lock_and_open(self.tempfile, retry=100, wait=0.1)
        except AcquireLockFailure:
            pass
        except InvalidFile:
            pass
        assert_that(file_io._lock_and_open.call_count, equal_to(101))
Esempio n. 3
0
 def setUp(self):
     self.file_io = _FileLock(DatastoreType.EXT3)
     self.tempfile = tempfile.mktemp()
Esempio n. 4
0
 def setUp(self):
     self.file_io = _FileLock(DatastoreType.EXT3)
     self.tempfile = tempfile.mktemp()