snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
This commit is contained in:
474
test/kafka/integration/rebalancing_test.go
Normal file
474
test/kafka/integration/rebalancing_test.go
Normal file
@@ -0,0 +1,474 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/IBM/sarama"
|
||||
"github.com/seaweedfs/seaweedfs/test/kafka/internal/testutil"
|
||||
)
|
||||
|
||||
// runConsumeLoop drives consumerGroup.Consume in a for-loop until ctx is cancelled
|
||||
// or the group is closed. This is the idiomatic Sarama pattern: Consume returns
|
||||
// when a rebalance cancels the session, and the caller is expected to re-enter.
|
||||
// Tests that observe rebalance behaviour MUST loop — otherwise the consumer goroutine
|
||||
// exits on the first rebalance and never sees the post-rebalance assignment.
|
||||
func runConsumeLoop(t *testing.T, ctx context.Context, name string, cg sarama.ConsumerGroup, topics []string, handler sarama.ConsumerGroupHandler) {
|
||||
for {
|
||||
if err := cg.Consume(ctx, topics, handler); err != nil {
|
||||
if ctx.Err() != nil || errors.Is(err, sarama.ErrClosedConsumerGroup) {
|
||||
return
|
||||
}
|
||||
t.Logf("%s Consume returned: %v (will retry)", name, err)
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testSingleConsumerAllPartitions(t *testing.T, addr, topicName, groupID string) {
|
||||
config := sarama.NewConfig()
|
||||
config.Consumer.Group.Rebalance.Strategy = sarama.BalanceStrategyRange
|
||||
config.Consumer.Offsets.Initial = sarama.OffsetOldest
|
||||
config.Consumer.Return.Errors = true
|
||||
|
||||
client, err := sarama.NewClient([]string{addr}, config)
|
||||
testutil.AssertNoError(t, err, "Failed to create client")
|
||||
defer client.Close()
|
||||
|
||||
consumerGroup, err := sarama.NewConsumerGroupFromClient(groupID, client)
|
||||
testutil.AssertNoError(t, err, "Failed to create consumer group")
|
||||
defer consumerGroup.Close()
|
||||
|
||||
handler := &RebalanceTestHandler{
|
||||
messages: make(chan *sarama.ConsumerMessage, 20),
|
||||
ready: make(chan bool),
|
||||
assignments: make(chan []int32, 1),
|
||||
t: t,
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Start consumer
|
||||
go func() {
|
||||
err := consumerGroup.Consume(ctx, []string{topicName}, handler)
|
||||
if err != nil && err != context.DeadlineExceeded {
|
||||
t.Logf("Consumer error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for consumer to be ready
|
||||
<-handler.ready
|
||||
|
||||
// Wait for assignment
|
||||
select {
|
||||
case partitions := <-handler.assignments:
|
||||
t.Logf("Single consumer assigned partitions: %v", partitions)
|
||||
if len(partitions) != 4 {
|
||||
t.Errorf("Expected single consumer to get all 4 partitions, got %d", len(partitions))
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("Timeout waiting for partition assignment")
|
||||
}
|
||||
|
||||
// Consume some messages to verify functionality
|
||||
consumedCount := 0
|
||||
for consumedCount < 4 { // At least one from each partition
|
||||
select {
|
||||
case msg := <-handler.messages:
|
||||
t.Logf("Consumed message from partition %d: %s", msg.Partition, string(msg.Value))
|
||||
consumedCount++
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Logf("Consumed %d messages so far", consumedCount)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if consumedCount == 0 {
|
||||
t.Error("No messages consumed by single consumer")
|
||||
}
|
||||
}
|
||||
|
||||
func testTwoConsumersRebalance(t *testing.T, addr, topicName, groupID string) {
|
||||
config := sarama.NewConfig()
|
||||
config.Consumer.Group.Rebalance.Strategy = sarama.BalanceStrategyRange
|
||||
config.Consumer.Offsets.Initial = sarama.OffsetOldest
|
||||
config.Consumer.Return.Errors = true
|
||||
|
||||
// Start first consumer
|
||||
client1, err := sarama.NewClient([]string{addr}, config)
|
||||
testutil.AssertNoError(t, err, "Failed to create client1")
|
||||
defer client1.Close()
|
||||
|
||||
consumerGroup1, err := sarama.NewConsumerGroupFromClient(groupID, client1)
|
||||
testutil.AssertNoError(t, err, "Failed to create consumer group 1")
|
||||
defer consumerGroup1.Close()
|
||||
|
||||
handler1 := &RebalanceTestHandler{
|
||||
messages: make(chan *sarama.ConsumerMessage, 20),
|
||||
ready: make(chan bool),
|
||||
assignments: make(chan []int32, 1),
|
||||
t: t,
|
||||
name: "Consumer1",
|
||||
}
|
||||
|
||||
ctx1, cancel1 := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel1()
|
||||
|
||||
go runConsumeLoop(t, ctx1, "Consumer1", consumerGroup1, []string{topicName}, handler1)
|
||||
|
||||
// Wait for first consumer to be ready and get initial assignment
|
||||
<-handler1.ready
|
||||
select {
|
||||
case partitions := <-handler1.assignments:
|
||||
t.Logf("Consumer1 initial assignment: %v", partitions)
|
||||
if len(partitions) != 4 {
|
||||
t.Errorf("Expected Consumer1 to initially get all 4 partitions, got %d", len(partitions))
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("Timeout waiting for Consumer1 initial assignment")
|
||||
}
|
||||
|
||||
// Start second consumer
|
||||
client2, err := sarama.NewClient([]string{addr}, config)
|
||||
testutil.AssertNoError(t, err, "Failed to create client2")
|
||||
defer client2.Close()
|
||||
|
||||
consumerGroup2, err := sarama.NewConsumerGroupFromClient(groupID, client2)
|
||||
testutil.AssertNoError(t, err, "Failed to create consumer group 2")
|
||||
defer consumerGroup2.Close()
|
||||
|
||||
handler2 := &RebalanceTestHandler{
|
||||
messages: make(chan *sarama.ConsumerMessage, 20),
|
||||
ready: make(chan bool),
|
||||
assignments: make(chan []int32, 1),
|
||||
t: t,
|
||||
name: "Consumer2",
|
||||
}
|
||||
|
||||
ctx2, cancel2 := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel2()
|
||||
|
||||
go runConsumeLoop(t, ctx2, "Consumer2", consumerGroup2, []string{topicName}, handler2)
|
||||
|
||||
// Wait for second consumer to be ready
|
||||
<-handler2.ready
|
||||
|
||||
// Wait for rebalancing to occur - both consumers should get new assignments
|
||||
var rebalancedAssignment1, rebalancedAssignment2 []int32
|
||||
|
||||
// Consumer1 should get a rebalance assignment
|
||||
select {
|
||||
case partitions := <-handler1.assignments:
|
||||
rebalancedAssignment1 = partitions
|
||||
t.Logf("Consumer1 rebalanced assignment: %v", partitions)
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Error("Timeout waiting for Consumer1 rebalance assignment")
|
||||
}
|
||||
|
||||
// Consumer2 should get its assignment
|
||||
select {
|
||||
case partitions := <-handler2.assignments:
|
||||
rebalancedAssignment2 = partitions
|
||||
t.Logf("Consumer2 assignment: %v", partitions)
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Error("Timeout waiting for Consumer2 assignment")
|
||||
}
|
||||
|
||||
// Verify rebalancing occurred correctly
|
||||
totalPartitions := len(rebalancedAssignment1) + len(rebalancedAssignment2)
|
||||
if totalPartitions != 4 {
|
||||
t.Errorf("Expected total of 4 partitions assigned, got %d", totalPartitions)
|
||||
}
|
||||
|
||||
// Each consumer should have at least 1 partition, and no more than 3
|
||||
if len(rebalancedAssignment1) == 0 || len(rebalancedAssignment1) > 3 {
|
||||
t.Errorf("Consumer1 should have 1-3 partitions, got %d", len(rebalancedAssignment1))
|
||||
}
|
||||
if len(rebalancedAssignment2) == 0 || len(rebalancedAssignment2) > 3 {
|
||||
t.Errorf("Consumer2 should have 1-3 partitions, got %d", len(rebalancedAssignment2))
|
||||
}
|
||||
|
||||
// Verify no partition overlap
|
||||
partitionSet := make(map[int32]bool)
|
||||
for _, p := range rebalancedAssignment1 {
|
||||
if partitionSet[p] {
|
||||
t.Errorf("Partition %d assigned to multiple consumers", p)
|
||||
}
|
||||
partitionSet[p] = true
|
||||
}
|
||||
for _, p := range rebalancedAssignment2 {
|
||||
if partitionSet[p] {
|
||||
t.Errorf("Partition %d assigned to multiple consumers", p)
|
||||
}
|
||||
partitionSet[p] = true
|
||||
}
|
||||
|
||||
t.Logf("Rebalancing test completed successfully")
|
||||
}
|
||||
|
||||
func testConsumerLeaveRebalance(t *testing.T, addr, topicName, groupID string) {
|
||||
config := sarama.NewConfig()
|
||||
config.Consumer.Group.Rebalance.Strategy = sarama.BalanceStrategyRange
|
||||
config.Consumer.Offsets.Initial = sarama.OffsetOldest
|
||||
config.Consumer.Return.Errors = true
|
||||
|
||||
// Start two consumers
|
||||
client1, err := sarama.NewClient([]string{addr}, config)
|
||||
testutil.AssertNoError(t, err, "Failed to create client1")
|
||||
defer client1.Close()
|
||||
|
||||
client2, err := sarama.NewClient([]string{addr}, config)
|
||||
testutil.AssertNoError(t, err, "Failed to create client2")
|
||||
defer client2.Close()
|
||||
|
||||
consumerGroup1, err := sarama.NewConsumerGroupFromClient(groupID, client1)
|
||||
testutil.AssertNoError(t, err, "Failed to create consumer group 1")
|
||||
defer consumerGroup1.Close()
|
||||
|
||||
consumerGroup2, err := sarama.NewConsumerGroupFromClient(groupID, client2)
|
||||
testutil.AssertNoError(t, err, "Failed to create consumer group 2")
|
||||
|
||||
handler1 := &RebalanceTestHandler{
|
||||
messages: make(chan *sarama.ConsumerMessage, 20),
|
||||
ready: make(chan bool),
|
||||
assignments: make(chan []int32, 1),
|
||||
t: t,
|
||||
name: "Consumer1",
|
||||
}
|
||||
|
||||
handler2 := &RebalanceTestHandler{
|
||||
messages: make(chan *sarama.ConsumerMessage, 20),
|
||||
ready: make(chan bool),
|
||||
assignments: make(chan []int32, 1),
|
||||
t: t,
|
||||
name: "Consumer2",
|
||||
}
|
||||
|
||||
ctx1, cancel1 := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel1()
|
||||
|
||||
ctx2, cancel2 := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
// Start both consumers with loops so they survive rebalance session exits.
|
||||
go runConsumeLoop(t, ctx1, "Consumer1", consumerGroup1, []string{topicName}, handler1)
|
||||
go runConsumeLoop(t, ctx2, "Consumer2", consumerGroup2, []string{topicName}, handler2)
|
||||
|
||||
// Wait for both consumers to be ready
|
||||
<-handler1.ready
|
||||
<-handler2.ready
|
||||
|
||||
// Wait for initial assignments
|
||||
<-handler1.assignments
|
||||
<-handler2.assignments
|
||||
|
||||
t.Logf("Both consumers started, now stopping Consumer2")
|
||||
|
||||
// Stop second consumer (simulate leave)
|
||||
cancel2()
|
||||
consumerGroup2.Close()
|
||||
|
||||
// Wait for Consumer1 to get rebalanced assignment (should get all partitions)
|
||||
select {
|
||||
case partitions := <-handler1.assignments:
|
||||
t.Logf("Consumer1 rebalanced assignment after Consumer2 left: %v", partitions)
|
||||
if len(partitions) != 4 {
|
||||
t.Errorf("Expected Consumer1 to get all 4 partitions after Consumer2 left, got %d", len(partitions))
|
||||
}
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Error("Timeout waiting for Consumer1 rebalance after Consumer2 left")
|
||||
}
|
||||
|
||||
t.Logf("Consumer leave rebalancing test completed successfully")
|
||||
}
|
||||
|
||||
func testMultipleConsumersJoin(t *testing.T, addr, topicName, groupID string) {
|
||||
config := sarama.NewConfig()
|
||||
config.Consumer.Group.Rebalance.Strategy = sarama.BalanceStrategyRange
|
||||
config.Consumer.Offsets.Initial = sarama.OffsetOldest
|
||||
config.Consumer.Return.Errors = true
|
||||
|
||||
numConsumers := 4
|
||||
consumers := make([]sarama.ConsumerGroup, numConsumers)
|
||||
clients := make([]sarama.Client, numConsumers)
|
||||
handlers := make([]*RebalanceTestHandler, numConsumers)
|
||||
contexts := make([]context.Context, numConsumers)
|
||||
cancels := make([]context.CancelFunc, numConsumers)
|
||||
|
||||
// Start all consumers simultaneously
|
||||
for i := 0; i < numConsumers; i++ {
|
||||
client, err := sarama.NewClient([]string{addr}, config)
|
||||
testutil.AssertNoError(t, err, fmt.Sprintf("Failed to create client%d", i))
|
||||
clients[i] = client
|
||||
|
||||
consumerGroup, err := sarama.NewConsumerGroupFromClient(groupID, client)
|
||||
testutil.AssertNoError(t, err, fmt.Sprintf("Failed to create consumer group %d", i))
|
||||
consumers[i] = consumerGroup
|
||||
|
||||
handlers[i] = &RebalanceTestHandler{
|
||||
messages: make(chan *sarama.ConsumerMessage, 20),
|
||||
ready: make(chan bool),
|
||||
assignments: make(chan []int32, 1),
|
||||
t: t,
|
||||
name: fmt.Sprintf("Consumer%d", i),
|
||||
}
|
||||
|
||||
contexts[i], cancels[i] = context.WithTimeout(context.Background(), 45*time.Second)
|
||||
|
||||
go func(idx int) {
|
||||
runConsumeLoop(t, contexts[idx], fmt.Sprintf("Consumer%d", idx),
|
||||
consumers[idx], []string{topicName}, handlers[idx])
|
||||
}(i)
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
defer func() {
|
||||
for i := 0; i < numConsumers; i++ {
|
||||
cancels[i]()
|
||||
consumers[i].Close()
|
||||
clients[i].Close()
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for all consumers to be ready. Four consumers racing in produces
|
||||
// several rebalance rounds; each round costs ~HeartbeatInterval (3s) before
|
||||
// the prior leader sees REBALANCE_IN_PROGRESS and rejoins. Give enough
|
||||
// headroom for the group to converge.
|
||||
for i := 0; i < numConsumers; i++ {
|
||||
select {
|
||||
case <-handlers[i].ready:
|
||||
t.Logf("Consumer%d ready", i)
|
||||
case <-time.After(30 * time.Second):
|
||||
t.Fatalf("Timeout waiting for Consumer%d to be ready", i)
|
||||
}
|
||||
}
|
||||
|
||||
// Collect the settled assignment for each consumer. Because each consumer's
|
||||
// Consume() returns and re-enters on every rebalance, Setup fires multiple
|
||||
// times while the group converges and the handler's assignments channel
|
||||
// accumulates several snapshots. Drain it and keep the most recent value.
|
||||
assignments := make([][]int32, numConsumers)
|
||||
deadline := time.Now().Add(20 * time.Second)
|
||||
for i := 0; i < numConsumers; i++ {
|
||||
select {
|
||||
case partitions := <-handlers[i].assignments:
|
||||
assignments[i] = partitions
|
||||
case <-time.After(time.Until(deadline)):
|
||||
t.Errorf("Timeout waiting for Consumer%d assignment", i)
|
||||
continue
|
||||
}
|
||||
drain:
|
||||
for {
|
||||
select {
|
||||
case partitions := <-handlers[i].assignments:
|
||||
assignments[i] = partitions
|
||||
case <-time.After(3 * time.Second):
|
||||
break drain
|
||||
}
|
||||
}
|
||||
t.Logf("Consumer%d final assignment: %v", i, assignments[i])
|
||||
}
|
||||
|
||||
// Verify all partitions are assigned exactly once
|
||||
assignedPartitions := make(map[int32]int)
|
||||
totalAssigned := 0
|
||||
for i, assignment := range assignments {
|
||||
totalAssigned += len(assignment)
|
||||
for _, partition := range assignment {
|
||||
assignedPartitions[partition]++
|
||||
if assignedPartitions[partition] > 1 {
|
||||
t.Errorf("Partition %d assigned to multiple consumers", partition)
|
||||
}
|
||||
}
|
||||
|
||||
// Each consumer should get exactly 1 partition (4 partitions / 4 consumers)
|
||||
if len(assignment) != 1 {
|
||||
t.Errorf("Consumer%d should get exactly 1 partition, got %d", i, len(assignment))
|
||||
}
|
||||
}
|
||||
|
||||
if totalAssigned != 4 {
|
||||
t.Errorf("Expected 4 total partitions assigned, got %d", totalAssigned)
|
||||
}
|
||||
|
||||
// Verify all partitions 0-3 are assigned
|
||||
for i := int32(0); i < 4; i++ {
|
||||
if assignedPartitions[i] != 1 {
|
||||
t.Errorf("Partition %d assigned %d times, expected 1", i, assignedPartitions[i])
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("Multiple consumers join test completed successfully")
|
||||
}
|
||||
|
||||
// RebalanceTestHandler implements sarama.ConsumerGroupHandler with rebalancing awareness
|
||||
type RebalanceTestHandler struct {
|
||||
messages chan *sarama.ConsumerMessage
|
||||
ready chan bool
|
||||
assignments chan []int32
|
||||
readyOnce sync.Once
|
||||
t *testing.T
|
||||
name string
|
||||
}
|
||||
|
||||
func (h *RebalanceTestHandler) Setup(session sarama.ConsumerGroupSession) error {
|
||||
h.t.Logf("%s: Consumer group session setup", h.name)
|
||||
h.readyOnce.Do(func() {
|
||||
close(h.ready)
|
||||
})
|
||||
|
||||
// Send partition assignment
|
||||
partitions := make([]int32, 0)
|
||||
for topic, partitionList := range session.Claims() {
|
||||
h.t.Logf("%s: Assigned topic %s with partitions %v", h.name, topic, partitionList)
|
||||
for _, partition := range partitionList {
|
||||
partitions = append(partitions, partition)
|
||||
}
|
||||
}
|
||||
|
||||
// Always publish the latest assignment. If the channel is full, drain one
|
||||
// stale value first so readers see the most recent rebalance outcome (not
|
||||
// whatever arrived first while the group was still converging).
|
||||
for {
|
||||
select {
|
||||
case h.assignments <- partitions:
|
||||
return nil
|
||||
default:
|
||||
select {
|
||||
case <-h.assignments:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *RebalanceTestHandler) Cleanup(sarama.ConsumerGroupSession) error {
|
||||
h.t.Logf("%s: Consumer group session cleanup", h.name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *RebalanceTestHandler) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
|
||||
for {
|
||||
select {
|
||||
case message := <-claim.Messages():
|
||||
if message == nil {
|
||||
return nil
|
||||
}
|
||||
h.t.Logf("%s: Received message from partition %d: %s", h.name, message.Partition, string(message.Value))
|
||||
select {
|
||||
case h.messages <- message:
|
||||
default:
|
||||
// Channel full, drop message for test
|
||||
}
|
||||
session.MarkMessage(message, "")
|
||||
case <-session.Context().Done():
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user