code: def test_resumed_with_different_resources(
      ws_with_running_task, done_ev_cls
  ):
      """A task with resources is cancelled and then resumed to the same state, but with
      different resources. This is actually possible in case of manual cancellation from
      the client, followed by resubmit.
      """
      ws = ws_with_running_task
      assert ws.available_resources == {"R": 0}
      ts = ws.tasks["x"]
      prev_state = ts.state
  
      ws.handle_stimulus(FreeKeysEvent(keys=["x"], stimulus_id="s1"))
      assert ws.available_resources == {"R": 0}
  
      instructions = ws.handle_stimulus(
          ComputeTaskEvent.dummy(
              "x", stimulus_id="s2", resource_restrictions={"R": 0.4}
          )
      )
      if prev_state == "long-running":
          assert instructions == [
              LongRunningMsg(
                  key="x", compute_duration=None, stimulus_id="s2"
              )
          ]
      else:
          assert not instructions
      assert ws.available_resources == {"R": 0}
  
      ws.handle_stimulus(done_ev_cls.dummy(key="x", stimulus_id="s3"))
      assert ws.available_resources == {"R": 1}
  
file_path: distributed/distributed/tests/test_resources.py
imports: from __future__ import annotations
  import asyncio
  import pytest
  import dask
  from dask import delayed
  from distributed import Lock, Worker
  from distributed.client import wait
  from distributed.utils_test import NO_AMM, gen_cluster, inc, lock_inc, slowadd, slowinc
  from distributed.worker_state_machine import ComputeTaskEvent, Execute, ExecuteFailureEvent, ExecuteSuccessEvent, FreeKeysEvent, LongRunningMsg, RescheduleEvent, TaskFinishedMsg
label_desc: Use image node_id 8 for calling a global function with example usage: test_resumed_with_different_resources(ws_with_running_task, done_ev_cls) without return types