code: def test_cancel_on_error_context_manager(mocker):
      executor = ThreadPoolExecutor(max_workers=2, cancel_on_error=True)
      spy = mocker.spy(executor, "shutdown")
      with pytest.raises(RuntimeError), executor:  # noqa: PT012
          future1 = executor.submit(operator.mul, 2, 21)
          future2 = executor.submit(time.sleep, 0.1)
          future3 = executor.submit(
              raiser(RuntimeError), "This is an error"
          )
          fs = [executor.submit(time.sleep, 0.1) for _ in range(50)]
  
          assert future1.result() == 42
          assert future2.result() is None
          _ = future3.result()
  
      spy.assert_called_once_with(wait=True, cancel_futures=True)
  
      cancelled = [fut for fut in fs if fut.cancelled()]
      others = [fut for fut in fs if not fut.cancelled()]
  
      for fut in others:
          assert fut.done()
          assert fut.exception() is None
  
      assert len(cancelled) > 20
      assert len(others) > 0
  
imports: import operator
  import time
  import pytest
  from funcy import raiser
  from dvc.utils.threadpool import ThreadPoolExecutor
label_desc: Use image node_id 2 for calling a global function with example usage: test_cancel_on_error_context_manager(mocker) without return types