mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Refactor picking a member function
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
5baf8377bb
commit
a5cfc089fa
@ -115,16 +115,9 @@ const (
|
||||
)
|
||||
|
||||
func (f goFailpoint) Trigger(t *testing.T, ctx context.Context, clus *e2e.EtcdProcessCluster) error {
|
||||
var member e2e.EtcdProcess
|
||||
switch f.target {
|
||||
case AnyMember:
|
||||
member = clus.Procs[rand.Int()%len(clus.Procs)]
|
||||
case Leader:
|
||||
member = clus.Procs[clus.WaitLeader(t)]
|
||||
default:
|
||||
panic("unknown target")
|
||||
}
|
||||
member := f.pickMember(t, clus)
|
||||
address := fmt.Sprintf("127.0.0.1:%d", member.Config().GoFailPort)
|
||||
|
||||
err := setupGoFailpoint(address, f.failpoint, f.payload)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gofailpoint setup failed: %w", err)
|
||||
@ -146,6 +139,17 @@ func (f goFailpoint) Trigger(t *testing.T, ctx context.Context, clus *e2e.EtcdPr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f goFailpoint) pickMember(t *testing.T, clus *e2e.EtcdProcessCluster) e2e.EtcdProcess {
|
||||
switch f.target {
|
||||
case AnyMember:
|
||||
return clus.Procs[rand.Int()%len(clus.Procs)]
|
||||
case Leader:
|
||||
return clus.Procs[clus.WaitLeader(t)]
|
||||
default:
|
||||
panic("unknown target")
|
||||
}
|
||||
}
|
||||
|
||||
func setupGoFailpoint(host, failpoint, payload string) error {
|
||||
failpointUrl := url.URL{
|
||||
Scheme: "http",
|
||||
|
Loading…
x
Reference in New Issue
Block a user