docstr: Tests that job-level conda env is GC'd when the job exits.
docstr_tok: ["Tests","that","job-level","conda","env","is","GC","'d","when","the","job","exits","."]
code: def test_job_level_gc(
      self,
      runtime_env_disable_URI_cache,
      start_cluster,
      field,
      spec_format,
      tmp_path,
  ):
      """Tests that job-level conda env is GC'd when the job exits."""
      # We must use a single-node cluster.  If we simulate a multi-node
      # cluster then the conda installs will proceed simultaneously, one on
      # each node, but since they're actually running on the same machine we
      # get errors.
      cluster, address = start_cluster
  
      ray.init(
          address,
          runtime_env=generate_runtime_env_dict(
              field, spec_format, tmp_path
          ),
      )
  
      @ray.remote
      def f():
          import pip_install_test  # noqa: F401
  
          return True
  
      # Ensure that the runtime env has been installed.
      assert ray.get(f.remote())
      # Sleep some seconds before checking that we didn't GC. Otherwise this
      # check may spuriously pass.
      time.sleep(2)
      assert not check_local_files_gced(cluster)
  
      ray.shutdown()
  
      wait_for_condition(
          lambda: check_local_files_gced(cluster), timeout=30
      )
  
      # Check that we can reconnect with the same env.  (In other words, ensure
      # the conda env was fully deleted and not left in some kind of corrupted
      # state that prevents reinstalling the same conda env.)
  
      ray.init(
          address,
          runtime_env=generate_runtime_env_dict(
              field, spec_format, tmp_path
          ),
      )
  
      assert ray.get(f.remote())
  
imports: import os
  import pytest
  import sys
  import platform
  import time
  from ray._private.test_utils import wait_for_condition, chdir, check_local_files_gced, generate_runtime_env_dict
  from ray._private.runtime_env.conda import _get_conda_dict_with_ray_inserted
  from ray._private.runtime_env.pip import INTERNAL_PIP_FILENAME, MAX_INTERNAL_PIP_FILENAME_TRIES, _PathHelper
  from ray.runtime_env import RuntimeEnv
  import yaml
  import tempfile
  from pathlib import Path
  import subprocess
  import ray
label_desc: Use image node_id 1 for calling the TestGC obj's underlying member method code with example usage: obj.test_job_level_gc(runtime_env_disable_URI_cache, start_cluster, field, spec_format, tmp_path) and returns: True