sarama icon indicating copy to clipboard operation
sarama copied to clipboard

fix: Adjust the retry count logic

Open AtlanCI opened this issue 3 years ago • 0 comments

Questions:

When the program first tries to connect to kafka, it specifies the number of retries as 3, which should normally be three, but it actually performs four attempts

Minimum recurrence:

func TestRefreshCount(t *testing.T) {
	seedBroker := NewMockBroker(t, 1)
	leader := NewMockBroker(t, 5)

	metadataResponse1 := new(MetadataResponse)
	metadataResponse1.AddBroker(leader.Addr(), leader.BrokerID())
	metadataResponse1.AddBroker(seedBroker.Addr(), seedBroker.BrokerID())
	seedBroker.Returns(metadataResponse1)
	config := NewTestConfig()
	config.Metadata.Retry.Max = 1
	client, err := NewClient([]string{seedBroker.Addr()}, config)
	if err != nil {
		t.Fatal(err)
	}

	if len(client.Brokers()) != 2 {
		t.Error("Meta broker is not 2")
	}

	metadataResponse2 := new(MetadataResponse)
	metadataResponse2.AddBroker(leader.Addr(), leader.BrokerID())
	seedBroker.Returns(metadataResponse2)

	if err := client.RefreshMetadata(); err != nil {
		t.Error(err)
	}
	if len(client.Brokers()) != 1 {
		t.Error("Meta broker is not 1")
	}
}

Also, add a tag to the tryRefreshMetadata in the client.go file image Results: image

Description:

The retry used here is defined temporarily and will be executed later. attemptsRemaining will still be executed later with the original attemptsRemaining (it should be minus one to include the current attempt in the retry count)

AtlanCI avatar Dec 23 '21 11:12 AtlanCI