code: def test_preempt_workers_ask_master(
      dummy: bool, auto_ack: bool
  ) -> None:
      with parallel.Execution(2) as pex:
          # Steal the automatically-created pex.distributed contexts, then test chief/worker serially
          # so we know they're not using distributed comms.
          @pex.run
          def distributed_contexts() -> core.DistributedContext:
              return pex.distributed
  
          # Test steps are identical for chief and worker.
          for dist in distributed_contexts:
              if not dummy:
                  state, context = make_test_preempt_context(
                      dist, core.PreemptMode.WorkersAskMaster
                  )
              else:
                  context = core.DummyPreemptContext(
                      dist, core.PreemptMode.WorkersAskMaster
                  )
              with context:
                  assert context.should_preempt() is False
                  if not dummy:
                      # No ack preemption calls yet.
                      state.mock_session.post.assert_not_called()
                      # Send the preemption signal.
                      state.preempt()
                      wait_on_watcher(context)
                      # Call again, to make sure we only ack once.
                      assert (
                          context.should_preempt(auto_ack=auto_ack)
                          is True
                      )
                      if auto_ack:
                          state.mock_session.post.assert_called_once()
                      else:
                          state.mock_session.post.assert_not_called()
  
file_path: determined/harness/tests/core/test_preempt.py
imports: import threading
  import time
  from typing import Any, Dict, Tuple
  from unittest import mock
  import pytest
  from determined import core
  from tests import parallel
label_desc: Use image node_id 5 for calling a global function with example usage: test_preempt_workers_ask_master(dummy, auto_ack) and returns: pex