Skip to content

Commit

Permalink
fix: INFRA-764 Fixed lingering bug in switchover test
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnitus- committed Feb 7, 2025
1 parent 70ed4b3 commit 9bb971e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions patroni/patroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,30 @@ func (pClient *PatroniClient) WaitForHealthy(timeout time.Duration, expectedCoun
func (pClient *PatroniClient) ForceLeaderChange(timeout time.Duration) error {
begining := time.Now()

switchRes, switchErr := pClient.Switchover(true)
if switchErr != nil {
return switchErr
}

cluster, clusterErr := pClient.GetCluster()
if clusterErr != nil {
return clusterErr
}

if switchRes.NewLeader == "" {
switchRes.NewLeader = cluster.GetLeader().Name
switchRes, switchErr := pClient.Switchover(true)
if switchErr != nil {
return switchErr
}

healthErr := pClient.WaitForHealthy(timeout, len(cluster.Members))
if healthErr != nil {
return healthErr
}

if switchRes.NewLeader == "" {
cluster, clusterErr = pClient.GetCluster()
if clusterErr != nil {
return clusterErr
}
switchRes.NewLeader = cluster.GetLeader().Name
}


pClient.log.Infof("Switchover from leader \"%s\" to leader \"%s\" with healthy cluster in %s", switchRes.PreviousLeader, switchRes.NewLeader, time.Now().Sub(begining).String())

return nil
Expand Down

0 comments on commit 9bb971e

Please sign in to comment.