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

Function Test_handleThrottledResponse

broker_test.go:1608–1702  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1606}
1607
1608func Test_handleThrottledResponse(t *testing.T) {
1609 mb := NewMockBroker(nil, 0)
1610 defer mb.Close()
1611 broker := NewBroker(mb.Addr())
1612 broker.id = 0
1613 conf := NewTestConfig()
1614 conf.Version = V1_0_0_0
1615 throttleTimeMs := 100
1616 throttleTime := time.Duration(throttleTimeMs) * time.Millisecond
1617 tests := []struct {
1618 name string
1619 response protocolBody
1620 expectDelay bool
1621 }{
1622 {
1623 name: "throttled response w/millisecond field",
1624 response: &MetadataResponse{
1625 ThrottleTimeMs: int32(throttleTimeMs),
1626 },
1627 expectDelay: true,
1628 },
1629 {
1630 name: "not throttled response w/millisecond field",
1631 response: &MetadataResponse{
1632 ThrottleTimeMs: 0,
1633 },
1634 },
1635 {
1636 name: "throttled response w/time.Duration field",
1637 response: &ProduceResponse{
1638 ThrottleTime: throttleTime,
1639 },
1640 expectDelay: true,
1641 },
1642 {
1643 name: "not throttled response w/time.Duration field",
1644 response: &ProduceResponse{
1645 ThrottleTime: time.Duration(0),
1646 },
1647 },
1648 {
1649 name: "not throttled response with no throttle time field",
1650 response: &SaslHandshakeResponse{},
1651 },
1652 }
1653 for _, tt := range tests {
1654 t.Run(tt.name, func(t *testing.T) {
1655 broker.metricRegistry = metrics.NewRegistry()
1656 broker.brokerThrottleTime = broker.registerHistogram("throttle-time-in-ms")
1657 startTime := time.Now()
1658 broker.handleThrottledResponse(tt.response)
1659 broker.waitIfThrottled()
1660 if tt.expectDelay {
1661 if time.Since(startTime) < throttleTime {
1662 t.Fatal("expected throttling to cause delay")
1663 }
1664 if broker.brokerThrottleTime.Min() != int64(throttleTimeMs) {
1665 t.Fatal("expected throttling to update metrics")

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
AddrMethod · 0.95
registerHistogramMethod · 0.95
waitIfThrottledMethod · 0.95
NewMockBrokerFunction · 0.85
NewBrokerFunction · 0.85
RunMethod · 0.80
FatalMethod · 0.80
StopMethod · 0.80
NewTestConfigFunction · 0.70

Tested by

no test coverage detected