Skip to content

Commit

Permalink
tests: Apply suggestions from code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed Feb 21, 2022
1 parent d6df64e commit 9a088c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
36 changes: 27 additions & 9 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) {
}
t.Logf("Cluster created")

t.Logf("etcdctl downgrade enable %s", lastVersion)
t.Logf("etcdctl downgrade enable %s", lastVersionStr)
downgradeEnable(t, epc, lastVersion)

t.Log("Downgrade enabled, validating if cluster is ready for downgrade")
Expand All @@ -65,9 +65,9 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) {
}
t.Log("Cluster is ready for downgrade")

t.Log("Starting downgrade process")
t.Logf("Starting downgrade process to %q", lastVersionStr)
for i := 0; i < len(epc.Procs); i++ {
t.Logf("Downgrading member %d", i)
t.Logf("Downgrading member %d by running %s binary", i, lastReleaseBinary)
stopEtcd(t, epc.Procs[i])
startEtcd(t, epc.Procs[i], lastReleaseBinary)
}
Expand All @@ -78,11 +78,14 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) {
}
t.Log("Downgrade complete")

t.Log("Starting upgrade process")
t.Logf("Starting upgrade process to %q", currentVersionStr)
for i := 0; i < len(epc.Procs); i++ {
t.Logf("Upgrading member %d", i)
stopEtcd(t, epc.Procs[i])
startEtcd(t, epc.Procs[i], currentEtcdBinary)
if i+1 < len(epc.Procs) {
validateVersion(t, epc.Cfg, epc.Procs[i], version.Versions{Cluster: lastVersionStr, Server: currentVersionStr})
}
}
t.Log("All members upgraded, validating upgrade")
for i := 0; i < len(epc.Procs); i++ {
Expand Down Expand Up @@ -180,10 +183,25 @@ func expectLog(t *testing.T, ep e2e.EtcdProcess, expectLog string) {

func leader(t *testing.T, epc *e2e.EtcdProcessCluster) e2e.EtcdProcess {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
leader, err := epc.Leader(ctx)
cancel()
if err != nil {
t.Fatal(err)
defer cancel()
for i := 0; i < len(epc.Procs); i++ {
endpoints := epc.Procs[i].EndpointsV3()
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: 3 * time.Second,
})
if err != nil {
t.Fatal(err)
}
defer cli.Close()
resp, err := cli.Status(ctx, endpoints[0])
if err != nil {
t.Fatal(err)
}
if resp.Header.GetMemberId() == resp.Leader {
return epc.Procs[i]
}
}
return leader
t.Fatal("Leader not found")
return nil
}
24 changes: 0 additions & 24 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package e2e

import (
"context"
"fmt"
"net/url"
"os"
Expand All @@ -24,7 +23,6 @@ import (
"testing"
"time"

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
Expand Down Expand Up @@ -493,25 +491,3 @@ func (epc *EtcdProcessCluster) WithStopSignal(sig os.Signal) (ret os.Signal) {
}
return ret
}
func (epc *EtcdProcessCluster) Leader(ctx context.Context) (EtcdProcess, error) {
for i := 0; i < len(epc.Procs); i++ {
endpoints := epc.Procs[i].EndpointsV3()
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: 3 * time.Second,
})
if err != nil {
return nil, err
}
defer cli.Close()
resp, err := cli.Status(ctx, endpoints[0])
if err != nil {
return nil, err
}
if resp.Header.GetMemberId() == resp.Leader {
return epc.Procs[i], nil
}
}

return nil, fmt.Errorf("Leader not found")
}

0 comments on commit 9a088c6

Please sign in to comment.