From 19e81e4ff3d240d667be1f049f09762f7d383fb1 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Thu, 14 Nov 2024 19:08:41 +0530 Subject: [PATCH] benchmark --- reader_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/reader_test.go b/reader_test.go index d777bc4a..ff59e9b3 100644 --- a/reader_test.go +++ b/reader_test.go @@ -1871,6 +1871,24 @@ func TestReaderClose(t *testing.T) { } } +func BenchmarkReaderClose(b *testing.B) { + r := NewReader(ReaderConfig{ + Brokers: []string{"localhost:9092"}, + Topic: makeTopic(), + MaxWait: 2 * time.Second, + }) + defer r.Close() + for i := 0; i < b.N; i++ { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + _, err := r.FetchMessage(ctx) + if err != context.DeadlineExceeded { + b.Errorf("bad err: %v", err) + } + } +} + // writeMessagesForCompactionCheck writes messages with specific writer configuration. func writeMessagesForCompactionCheck(t *testing.T, topic string, msgs []Message) { t.Helper()