code: def _test_invoke_on_rank_and_broadcast_result(
      cls,
      rank: int,
      world_size: int,
      backend: str,
  ) -> None:
      dist.init_process_group(
          rank=rank, world_size=world_size, backend=backend
      )
      pg = dist.new_group(
          ranks=[0, 1],
          backend=backend,
      )
  
      func = mock.MagicMock()
      func.return_value = pg.rank()
  
      res = invoke_on_rank_and_broadcast_result(
          pg=pg, rank=0, func=func
      )
      assert res == 0, f"Expect res to be 0 (got {res})"
  
      if pg.rank() == 0:
          func.assert_called_once()
      else:
          func.assert_not_called()
      func.reset_mock()
  
      res = invoke_on_rank_and_broadcast_result(
          pg=pg, rank=1, func=func
      )
      assert res == 1, f"Expect res to be 1 (got {res})"
  
      if pg.rank() == 0:
          func.assert_not_called()
      else:
          func.assert_called_once()
  
      dist.destroy_process_group()
  
imports: import multiprocessing
  import os
  import unittest
  from typing import Callable
  from unittest import mock
  import torch.distributed
  from torch._utils_internal import TEST_MASTER_ADDR
  from torchrec.distributed.collective_utils import invoke_on_rank_and_broadcast_result, is_leader, run_on_leader
  from torchrec.test_utils import get_free_port, seed_and_log
label_desc: Use image node_id 6 for calling the CollectiveUtilsTest obj's underlying member method code with example usage: obj._test_invoke_on_rank_and_broadcast_result(cls, rank, world_size, backend) without return types