code: def test_connect_timeout(_socket, conn):
      assert conn.state is ConnectionStates.DISCONNECTED
  
      # Initial connect returns EINPROGRESS
      # immediate inline connect returns EALREADY
      # second explicit connect returns EALREADY
      # third explicit connect returns EALREADY and times out via last_attempt
      _socket.connect_ex.side_effect = [
          EINPROGRESS,
          EALREADY,
          EALREADY,
          EALREADY,
      ]
      conn.connect()
      assert conn.state is ConnectionStates.CONNECTING
      conn.connect()
      assert conn.state is ConnectionStates.CONNECTING
      conn.last_attempt = 0
      conn.connect()
      assert conn.state is ConnectionStates.DISCONNECTED
  
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 5 for calling a global function with example usage: test_connect_timeout(_socket, conn) without return types