

@mock.patch('socket.create_connection')
def test_copy_thread(self, socket):
    'KafkaConnection copies work in other threads'
    err = []
    copy = KafkaConnection('kafka', 9092).copy()

    def thread_func(err, copy):
        try:
            self.assertEqual(copy.host, 'kafka')
            self.assertEqual(copy.port, 9092)
            self.assertNotEqual(copy._sock, None)
        except Exception as e:
            err.append(e)
        else:
            err.append(None)
    thread = Thread(target=thread_func, args=(err, copy))
    thread.start()
    thread.join()
    self.assertEqual(err, [None])
    self.assertEqual(socket.call_count, 2)

dataset/ETHPy150Open dpkp/kafka-python/test/test_conn_legacy.py TestKafkaConnection.test_copy_thread/original