github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/batch_test.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "errors" 6 "io" 7 "net" 8 "strconv" 9 "testing" 10 ) 11 12 func TestBatchDontExpectEOF(t *testing.T) { 13 topic := makeTopic() 14 15 broker, err := (&Dialer{ 16 Resolver: &net.Resolver{}, 17 }).LookupLeader(context.Background(), "tcp", "localhost:9092", topic, 0) 18 if err != nil { 19 t.Fatal("failed to open a new kafka connection:", err) 20 } 21 22 nc, err := net.Dial("tcp", net.JoinHostPort(broker.Host, strconv.Itoa(broker.Port))) 23 if err != nil { 24 t.Fatalf("cannot connect to partition leader at %s:%d: %s", broker.Host, broker.Port, err) 25 } 26 27 conn := NewConn(nc, topic, 0) 28 defer conn.Close() 29 30 nc.(*net.TCPConn).CloseRead() 31 32 batch := conn.ReadBatch(1024, 8192) 33 34 if _, err := batch.ReadMessage(); !errors.Is(err, io.ErrUnexpectedEOF) { 35 t.Error("bad error when reading message:", err) 36 } 37 38 if err := batch.Close(); !errors.Is(err, io.ErrUnexpectedEOF) { 39 t.Error("bad error when closing the batch:", err) 40 } 41 }