code: def test_fail_fast(
      ray_start_4_cpus_2_gpus_extra, resource_manager_cls, fail_fast
  ):
      """Test fail_fast feature.
  
      If fail_fast=True, after the first failure, all other trials should be terminated
      (because we end the experiment).
  
      If fail_fast=RAISE, after the first failure, we should raise an error.
  
      Legacy test: test_trial_runner_2.py::TrialRunnerTest::testFailFast
      Legacy test: test_trial_runner_2.py::TrialRunnerTest::testFailFastRaise
      """
  
      runner = TuneController(
          resource_manager_factory=lambda: resource_manager_cls(),
          fail_fast=fail_fast,
          storage=STORAGE,
      )
      kwargs = {
          "placement_group_factory": PlacementGroupFactory(
              [{"CPU": 1, "GPU": 1}]
          ),
          "checkpoint_config": CheckpointConfig(checkpoint_frequency=1),
          "max_failures": 0,
          "config": {
              "mock_error": True,
              "persistent_error": True,
          },
          "storage": STORAGE,
      }
      runner.add_trial(Trial("__fake", **kwargs))
      runner.add_trial(Trial("__fake", **kwargs))
      trials = runner.get_trials()
  
      if fail_fast == TuneController.RAISE:
          with pytest.raises(Exception):
              while not runner.is_finished():
                  runner.step()
          runner.cleanup()
          return
      else:
          while not runner.is_finished():
              runner.step()
  
      status_count = Counter(t.status for t in trials)
  
      # One trial failed
      assert status_count.get(Trial.ERROR) == 1
      # The other one was pre-empted
      assert status_count.get(Trial.TERMINATED) == 1
  
      # Controller finished
      with pytest.raises(TuneError):
          runner.step()
  
imports: import os
  from collections import Counter
  import pytest
  import sys
  import ray
  from ray.train import CheckpointConfig
  from ray.air.execution import FixedResourceManager, PlacementGroupResourceManager
  from ray.tune import PlacementGroupFactory, TuneError
  from ray.tune.execution.tune_controller import TuneController
  from ray.tune.experiment import Trial
  from ray.tune.registry import TRAINABLE_CLASS, _global_registry
  from ray.tune.schedulers import FIFOScheduler
  from ray.tune.search import BasicVariantGenerator
  from ray.train.tests.util import mock_storage_context
  from ray.tune.tests.execution.utils import BudgetResourceManager
label_desc: Use image node_id 6 for calling a global function with example usage: test_fail_fast(ray_start_4_cpus_2_gpus_extra, resource_manager_cls, fail_fast) without return types