Пример #1
0
  def testAbandondedLockFile(self):
    # Tests that the caching procedure is resilient to an abandonded lock
    # file.
    FLAGS.tfhub_cache_dir = os.path.join(self.get_temp_dir(), "cache_dir")

    # Create an "abandoned" lock file, i.e. a lock file with no process actively
    # downloading anymore.
    module_dir = compressed_module_resolver._module_dir(self.module_handle)
    task_uid = uuid.uuid4().hex
    lock_filename = resolver._lock_filename(module_dir)
    tf_utils.atomic_write_string_to_file(lock_filename,
                                         resolver._lock_file_contents(task_uid),
                                         overwrite=False)
    with mock.patch.object(
        compressed_module_resolver.HttpCompressedFileResolver,
        "_lock_file_timeout_sec",
        return_value=10):
      http_resolver = compressed_module_resolver.HttpCompressedFileResolver()
      handle = "http://localhost:%d/mock_module.tar.gz" % self.server_port
      # After seeing the lock file is abandoned, this resolver will download the
      # module and return a path to the extracted contents.
      path = http_resolver(handle)
    files = os.listdir(path)
    self.assertListEqual(sorted(files), ["file1", "file2", "file3"])
    self.assertFalse(tf.gfile.Exists(lock_filename))
Пример #2
0
    def testAbandondedLockFile(self):
        # Tests that the caching procedure is resilient to an abandonded lock
        # file.
        FLAGS.tfhub_cache_dir = os.path.join(self.get_temp_dir(), "cache_dir")

        # Create an "abandoned" lock file, i.e. a lock file with no process actively
        # downloading anymore.
        module_dir = compressed_module_resolver._module_dir(self.module_handle)
        task_uid = uuid.uuid4().hex
        lock_filename = resolver._lock_filename(module_dir)
        tf_utils.atomic_write_string_to_file(
            lock_filename,
            resolver._lock_file_contents(task_uid),
            overwrite=False)
        with mock.patch.object(
                compressed_module_resolver.HttpCompressedFileResolver,
                "_lock_file_timeout_sec",
                return_value=10):
            http_resolver = compressed_module_resolver.HttpCompressedFileResolver(
            )
            handle = "http://localhost:%d/mock_module.tar.gz" % self.server_port
            # After seeing the lock file is abandoned, this resolver will download the
            # module and return a path to the extracted contents.
            path = http_resolver(handle)
        files = os.listdir(path)
        self.assertListEqual(sorted(files), ["file1", "file2", "file3"])
        self.assertFalse(tf.compat.v1.gfile.Exists(lock_filename))