code: def _socket(mocker):
      socket = mocker.MagicMock()
      socket.connect_ex.return_value = 0
      mocker.patch("socket.socket", return_value=socket)
      return socket
  
imports: from __future__ import absolute_import
  from errno import EALREADY, EINPROGRESS, EISCONN, ECONNRESET
  import socket
  import mock
  import pytest
  from kafka.conn import BrokerConnection, ConnectionStates, collect_hosts
  from kafka.protocol.api import RequestHeader
  from kafka.protocol.metadata import MetadataRequest
  from kafka.protocol.produce import ProduceRequest
  import kafka.errors
label_desc: Use image node_id 2 for calling a global function with example usage: _socket(mocker) and returns: socket