Files
seaweedfs/test/kafka/consumer_only_test.go
T
chrislu 4bca5a5d48 mq(kafka): fix JoinGroup request parsing - major debugging breakthrough!
 FIXED: JoinGroup request parsing error that was causing error responses
- Fixed test data: group ID 'debug-group' is 11 bytes, not 10
- JoinGroup now parses correctly and returns valid responses
- Manual JoinGroup test shows perfect parsing (200 bytes response)

 REMAINING ISSUE: kafka-go still restarts consumer group workflow
- JoinGroup response is syntactically correct but semantically rejected
- kafka-go closes connection immediately after JoinGroup response
- No SyncGroup calls - suggests response content issue

Next: Investigate JoinGroup response content compatibility with kafka-go
2025-09-10 20:58:36 -07:00

74 lines
1.9 KiB
Go

package kafka
import (
"context"
"fmt"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/mq/kafka/gateway"
"github.com/segmentio/kafka-go"
)
// TestConsumerOnly tests only the consumer workflow to debug SyncGroup issue
func TestConsumerOnly(t *testing.T) {
// Start gateway server
gatewayServer := gateway.NewServer(gateway.Options{
Listen: ":0", // random port
})
go func() {
if err := gatewayServer.Start(); err != nil {
t.Errorf("Gateway server error: %v", err)
}
}()
defer gatewayServer.Close()
// Wait for server to start
time.Sleep(100 * time.Millisecond)
// Get the actual listening address
host, port := gatewayServer.GetListenerAddr()
brokerAddr := fmt.Sprintf("%s:%d", host, port)
t.Logf("Gateway running on %s", brokerAddr)
// Get handler and configure it
handler := gatewayServer.GetHandler()
handler.SetBrokerAddress(host, port)
// Add test topic and some fake messages
topicName := "consumer-test-topic"
handler.AddTopicForTesting(topicName, 1)
t.Log("=== STARTING CONSUMER ONLY TEST ===")
// Create consumer
reader := kafka.NewReader(kafka.ReaderConfig{
Brokers: []string{brokerAddr},
Topic: topicName,
GroupID: "consumer-test-group",
MinBytes: 1,
MaxBytes: 10e6, // 10MB
MaxWait: 2 * time.Second, // Short wait to see pattern quickly
})
defer reader.Close()
// Try to read a message with a short timeout
// This should trigger the consumer group workflow
t.Log("Attempting to read message (will trigger consumer group workflow)...")
// Use context with timeout instead of SetDeadline
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
defer cancel()
_, err := reader.ReadMessage(ctx)
if err != nil {
t.Logf("ReadMessage failed (expected): %v", err)
// This is expected since we don't have real messages
} else {
t.Log("ReadMessage succeeded unexpectedly")
}
t.Log("=== CONSUMER TEST COMPLETED ===")
}