MoveLeader moves the leader to the ith process.
(ctx context.Context, t testing.TB, i int)
| 1177 | |
| 1178 | // MoveLeader moves the leader to the ith process. |
| 1179 | func (epc *EtcdProcessCluster) MoveLeader(ctx context.Context, t testing.TB, i int) error { |
| 1180 | if i < 0 || i >= len(epc.Procs) { |
| 1181 | return fmt.Errorf("invalid index: %d, must between 0 and %d", i, len(epc.Procs)-1) |
| 1182 | } |
| 1183 | t.Logf("moving leader to Procs[%d]", i) |
| 1184 | oldLeader := epc.WaitMembersForLeader(ctx, t, epc.Procs) |
| 1185 | if oldLeader == i { |
| 1186 | t.Logf("Procs[%d] is already the leader", i) |
| 1187 | return nil |
| 1188 | } |
| 1189 | resp, err := epc.Procs[i].Etcdctl().Status(ctx) |
| 1190 | if err != nil { |
| 1191 | return err |
| 1192 | } |
| 1193 | memberID := resp[0].Header.MemberId |
| 1194 | err = epc.Procs[oldLeader].Etcdctl().MoveLeader(ctx, memberID) |
| 1195 | if err != nil { |
| 1196 | return err |
| 1197 | } |
| 1198 | newLeader := epc.WaitMembersForLeader(ctx, t, epc.Procs) |
| 1199 | if newLeader != i { |
| 1200 | t.Fatalf("expect new leader to be Procs[%d] but got Procs[%d]", i, newLeader) |
| 1201 | } |
| 1202 | t.Logf("moved leader from Procs[%d] to Procs[%d]", oldLeader, i) |
| 1203 | return nil |
| 1204 | } |
nothing calls this directly
no test coverage detected