(t *testing.T)
| 1606 | } |
| 1607 | |
| 1608 | func 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") |
nothing calls this directly
no test coverage detected