orchestrator/kafka: force metadata refresh during tests

New versions of kadm cache metadata by default. Ask a refresh to avoid
that.
This commit is contained in:
Vincent Bernat
2025-10-22 08:31:30 +02:00
parent eca3ff01b8
commit 4390c89c52
2 changed files with 9 additions and 1 deletions

View File

@@ -144,6 +144,7 @@ func TestTopicMorePartitions(t *testing.T) {
deadline := time.Now().Add(1 * time.Second)
for {
client.ForceMetadataRefresh()
topics, err := adminClient.ListTopics(t.Context())
if err != nil {
t.Fatalf("ListTopics() error:\n%+v", err)
@@ -177,11 +178,15 @@ func TestTopicMorePartitions(t *testing.T) {
deadline = time.Now().Add(1 * time.Second)
for {
client.ForceMetadataRefresh()
topics, err := adminClient.ListTopics(t.Context())
if err != nil {
t.Fatalf("ListTopics() error:\n%+v", err)
}
topic := topics[expectedTopicName]
topic, ok := topics[expectedTopicName]
if !ok {
t.Fatal("ListTopics() did not find the topic")
}
t.Logf("Topic configuration:\n%+v", topic)
if len(topic.Partitions) != 4 || topic.Partitions.NumReplicas() != 1 {
if time.Now().Before(deadline) {

View File

@@ -82,6 +82,7 @@ func (c *Component) Start() error {
return fmt.Errorf("unable to create topic %q: %w", c.kafkaTopic, err)
}
l.Info().Msg("topic created")
client.ForceMetadataRefresh()
} else {
nbPartitions := len(topic.Partitions)
if nbPartitions > int(c.config.TopicConfiguration.NumPartitions) {
@@ -95,6 +96,7 @@ func (c *Component) Start() error {
c.kafkaTopic, err)
}
l.Info().Msg("number of partitions increased")
client.ForceMetadataRefresh()
}
if int(c.config.TopicConfiguration.ReplicationFactor) != topic.Partitions.NumReplicas() {
// TODO: https://github.com/deviceinsight/kafkactl/blob/main/internal/topic/topic-operation.go
@@ -136,6 +138,7 @@ func (c *Component) Start() error {
c.kafkaTopic, err)
}
l.Info().Msg("topic updated")
client.ForceMetadataRefresh()
}
}
return nil