|
6 | 6 | "sync"
|
7 | 7 | "testing"
|
8 | 8 | "time"
|
| 9 | + |
| 10 | + assert "github.com/stretchr/testify/require" |
9 | 11 | )
|
10 | 12 |
|
11 | 13 | type handler struct {
|
@@ -200,3 +202,46 @@ outerFor:
|
200 | 202 |
|
201 | 203 | cancel()
|
202 | 204 | }
|
| 205 | + |
| 206 | +// TestConsumerGroupSessionDoesNotRetryForever ensures that an error fetching |
| 207 | +// the coordinator decrements the retry attempts and doesn't end up retrying |
| 208 | +// forever |
| 209 | +func TestConsumerGroupSessionDoesNotRetryForever(t *testing.T) { |
| 210 | + config := NewTestConfig() |
| 211 | + config.ClientID = t.Name() |
| 212 | + config.Version = V2_0_0_0 |
| 213 | + config.Consumer.Return.Errors = true |
| 214 | + config.Consumer.Group.Rebalance.Retry.Max = 1 |
| 215 | + config.Consumer.Group.Rebalance.Retry.Backoff = 0 |
| 216 | + |
| 217 | + broker0 := NewMockBroker(t, 0) |
| 218 | + |
| 219 | + broker0.SetHandlerByMap(map[string]MockResponse{ |
| 220 | + "MetadataRequest": NewMockMetadataResponse(t). |
| 221 | + SetBroker(broker0.Addr(), broker0.BrokerID()). |
| 222 | + SetLeader("my-topic", 0, broker0.BrokerID()), |
| 223 | + "FindCoordinatorRequest": NewMockFindCoordinatorResponse(t). |
| 224 | + SetError(CoordinatorGroup, "my-group", ErrGroupAuthorizationFailed), |
| 225 | + }) |
| 226 | + |
| 227 | + group, err := NewConsumerGroup([]string{broker0.Addr()}, "my-group", config) |
| 228 | + if err != nil { |
| 229 | + t.Fatal(err) |
| 230 | + } |
| 231 | + defer func() { _ = group.Close() }() |
| 232 | + |
| 233 | + ctx, cancel := context.WithCancel(context.Background()) |
| 234 | + h := &handler{t, cancel} |
| 235 | + |
| 236 | + var wg sync.WaitGroup |
| 237 | + wg.Add(1) |
| 238 | + |
| 239 | + go func() { |
| 240 | + topics := []string{"my-topic"} |
| 241 | + err := group.Consume(ctx, topics, h) |
| 242 | + assert.Error(t, err) |
| 243 | + wg.Done() |
| 244 | + }() |
| 245 | + |
| 246 | + wg.Wait() |
| 247 | +} |
0 commit comments