code: def test_lookup_on_connect():
      hostname = "example.org"
      port = 9092
      conn = BrokerConnection(hostname, port, socket.AF_UNSPEC)
      assert conn.host == hostname
      assert conn.port == port
      assert conn.afi == socket.AF_UNSPEC
      afi1 = socket.AF_INET
      sockaddr1 = ("127.0.0.1", 9092)
      mock_return1 = [
          (afi1, socket.SOCK_STREAM, 6, "", sockaddr1),
      ]
      with mock.patch(
          "socket.getaddrinfo", return_value=mock_return1
      ) as m:
          conn.connect()
          m.assert_called_once_with(
              hostname, port, 0, socket.SOCK_STREAM
          )
          assert conn._sock_afi == afi1
          assert conn._sock_addr == sockaddr1
          conn.close()
  
      afi2 = socket.AF_INET6
      sockaddr2 = ("::1", 9092, 0, 0)
      mock_return2 = [
          (afi2, socket.SOCK_STREAM, 6, "", sockaddr2),
      ]
  
      with mock.patch(
          "socket.getaddrinfo", return_value=mock_return2
      ) as m:
          conn.last_attempt = 0
          conn.connect()
          m.assert_called_once_with(
              hostname, port, 0, socket.SOCK_STREAM
          )
          assert conn._sock_afi == afi2
          assert conn._sock_addr == sockaddr2
          conn.close()
  
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 24 for calling a global function with example usage: test_lookup_on_connect() without return types