MCPcopy
hub / github.com/IBM/sarama / TestClusterAdminListTopicsRetriesOnDescribeConfigsTimeout

Function TestClusterAdminListTopicsRetriesOnDescribeConfigsTimeout

admin_test.go:278–346  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

276}
277
278func TestClusterAdminListTopicsRetriesOnDescribeConfigsTimeout(t *testing.T) {
279 seedBroker := NewMockBroker(t, 1)
280 defer seedBroker.Close()
281
282 metadataResponse := NewMockMetadataResponse(t).
283 SetController(seedBroker.BrokerID()).
284 SetBroker(seedBroker.Addr(), seedBroker.BrokerID()).
285 SetLeader("my_topic", 0, seedBroker.BrokerID())
286
287 var stateMu sync.Mutex
288 var injectTimeout, injected bool
289 var describeConfigsAttempts int
290 describeConfigsResponse := NewMockDescribeConfigsResponse(t)
291
292 seedBroker.SetHandlerFuncByMap(map[string]requestHandlerFunc{
293 "MetadataRequest": func(req *request) encoderWithHeader {
294 return metadataResponse.For(req.body)
295 },
296 "DescribeConfigsRequest": func(req *request) encoderWithHeader {
297 stateMu.Lock()
298 describeConfigsAttempts++
299 shouldInject := injectTimeout && !injected
300 if shouldInject {
301 injected = true
302 }
303 stateMu.Unlock()
304 if shouldInject {
305 return nil
306 }
307 return describeConfigsResponse.For(req.body)
308 },
309 })
310
311 config := NewTestConfig()
312 config.Version = V1_1_0_0
313 config.Net.ReadTimeout = 100 * time.Millisecond
314 config.Admin.Retry.Max = 3
315 config.Admin.Retry.Backoff = 10 * time.Millisecond
316
317 admin, err := NewClusterAdmin([]string{seedBroker.Addr()}, config)
318 if err != nil {
319 t.Fatal(err)
320 }
321 defer safeClose(t, admin)
322
323 stateMu.Lock()
324 injectTimeout = true
325 describeConfigsAttemptsBeforeList := describeConfigsAttempts
326 stateMu.Unlock()
327
328 entries, err := admin.ListTopics()
329 if err != nil {
330 t.Fatal(err)
331 }
332
333 stateMu.Lock()
334 gotInjected := injected
335 gotDescribeConfigsAttempts := describeConfigsAttempts

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
BrokerIDMethod · 0.95
AddrMethod · 0.95
SetHandlerFuncByMapMethod · 0.95
ForMethod · 0.95
ListTopicsMethod · 0.95
NewMockBrokerFunction · 0.85
NewMockMetadataResponseFunction · 0.85
NewClusterAdminFunction · 0.85
SetLeaderMethod · 0.80
SetBrokerMethod · 0.80

Tested by

no test coverage detected