code: def test_search_alg_scheduler_stop(
      ray_start_4_cpus_2_gpus_extra, resource_manager_cls
  ):
      """Check that a scheduler-issued stop also notifies the search algorithm.
  
      Legacy test: test_trial_runner_3.py::TrialRunnerTest::testSearchAlgSchedulerInteraction  # noqa
      """
  
      class _MockScheduler(FIFOScheduler):
          def on_trial_result(self, *args, **kwargs):
              return TrialScheduler.STOP
  
      experiment_spec = {
          "run": "__fake",
          "stop": {"training_iteration": 5},
      }
      experiments = [Experiment.from_json("test", experiment_spec)]
      search_alg = _MockSuggestionAlgorithm()
      searcher = search_alg.searcher
      search_alg.add_configurations(experiments)
  
      runner = TestTuneController(
          resource_manager_factory=lambda: resource_manager_cls(),
          search_alg=search_alg,
          scheduler=_MockScheduler(),
      )
  
      trials = runner.get_trials()
  
      while not runner.is_finished():
          runner.step()
  
      # Result is not processed because trial stop takes precedence
      assert searcher.counter["result"] == 0
      # But on_trial_complete is triggered...
      assert searcher.counter["complete"] == 1
      # ... and still updates the last result.
      assert trials[0].last_result[TRAINING_ITERATION] == 1
  
imports: import os
  import pickle
  from collections import Counter
  import pytest
  import sys
  import ray
  from ray.air.constants import TRAINING_ITERATION
  from ray.air.execution import FixedResourceManager, PlacementGroupResourceManager
  from ray.tune import Experiment, PlacementGroupFactory
  from ray.tune.execution.tune_controller import TuneController
  from ray.tune.experiment import Trial
  from ray.tune.schedulers import FIFOScheduler, TrialScheduler
  from ray.tune.search import Searcher, ConcurrencyLimiter, Repeater, SearchGenerator
  from ray.tune.search._mock import _MockSuggestionAlgorithm
  from ray.train.tests.util import mock_storage_context
label_desc: Use image node_id 4 for calling a global function with example usage: test_search_alg_scheduler_stop(ray_start_4_cpus_2_gpus_extra, resource_manager_cls) and returns: TrialScheduler