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

Function TestClientMetadataTimeout

client_test.go:932–1018  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

930}
931
932func TestClientMetadataTimeout(t *testing.T) {
933 tests := []struct {
934 name string
935 timeout time.Duration
936 }{
937 {
938 "timeout=250ms",
939 250 * time.Millisecond, // Will cut the first retry pass
940 },
941 {
942 "timeout=500ms",
943 500 * time.Millisecond, // Will cut the second retry pass
944 },
945 {
946 "timeout=750ms",
947 750 * time.Millisecond, // Will cut the third retry pass
948 },
949 {
950 "timeout=900ms",
951 900 * time.Millisecond, // Will stop after the three retries
952 },
953 }
954
955 for _, singleFlight := range []bool{true, false} {
956 for _, tc := range tests {
957 t.Run(fmt.Sprintf("%s_singleflight_is_%t", tc.name, singleFlight), func(t *testing.T) {
958 // Use a responsive broker to create a working client
959 initialSeed := NewMockBroker(t, 0)
960 emptyMetadata := new(MetadataResponse)
961 emptyMetadata.AddBroker(initialSeed.Addr(), initialSeed.BrokerID())
962 initialSeed.Returns(emptyMetadata)
963
964 conf := NewTestConfig()
965 // Speed up the metadata request failure because of a read timeout
966 conf.Net.ReadTimeout = 100 * time.Millisecond
967 // Disable backoff and refresh
968 conf.Metadata.Retry.Backoff = 0
969 conf.Metadata.RefreshFrequency = 0
970 // But configure a "global" timeout
971 conf.Metadata.Timeout = tc.timeout
972 conf.Metadata.SingleFlight = singleFlight
973 c, err := NewClient([]string{initialSeed.Addr()}, conf)
974 if err != nil {
975 t.Fatal(err)
976 }
977 initialSeed.Close()
978
979 client := c.(*client)
980
981 // Start seed brokers that do not reply to anything and therefore a read
982 // on the TCP connection will timeout to simulate unresponsive brokers
983 seed1 := NewMockBroker(t, 1)
984 defer seed1.Close()
985 seed2 := NewMockBroker(t, 2)
986 defer seed2.Close()
987
988 // Overwrite the seed brokers with a fixed ordering to make this test deterministic
989 safeClose(t, client.seedBrokers[0])

Callers

nothing calls this directly

Calls 15

AddrMethod · 0.95
BrokerIDMethod · 0.95
ReturnsMethod · 0.95
CloseMethod · 0.95
RefreshMetadataMethod · 0.95
NewMockBrokerFunction · 0.85
NewBrokerFunction · 0.85
RunMethod · 0.80
AddBrokerMethod · 0.80
FatalMethod · 0.80
IsMethod · 0.80
FatalfMethod · 0.80

Tested by

no test coverage detected