Skip to content

Commit

Permalink
Merge pull request #14344 from clarkfw/common-framework-share-constants
Browse files Browse the repository at this point in the history
tests: e2e and integration share TickDuration constant
  • Loading branch information
spzala authored Aug 15, 2022
2 parents 012fc51 + 0b9f434 commit a1405e9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
4 changes: 4 additions & 0 deletions tests/framework/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

package config

import "time"

type TLSConfig string

const (
NoTLS TLSConfig = ""
AutoTLS TLSConfig = "auto-tls"
ManualTLS TLSConfig = "manual-tls"

TickDuration = 10 * time.Millisecond
)

type ClusterConfig struct {
Expand Down
6 changes: 2 additions & 4 deletions tests/framework/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

const TickDuration = 10 * time.Millisecond

type e2eRunner struct{}

func (e e2eRunner) TestMain(m *testing.M) {
Expand Down Expand Up @@ -116,7 +114,7 @@ func (c *e2eCluster) WaitMembersForLeader(ctx context.Context, t testing.TB, mem
t.Fatal("WaitMembersForLeader timeout")
default:
}
_, err := cc.Get("0", config.GetOptions{Timeout: 10*TickDuration + time.Second})
_, err := cc.Get("0", config.GetOptions{Timeout: 10*config.TickDuration + time.Second})
if err == nil || strings.Contains(err.Error(), "Key not found") {
break
}
Expand Down Expand Up @@ -149,7 +147,7 @@ func (c *e2eCluster) WaitMembersForLeader(ctx context.Context, t testing.TB, mem
}
leaders = make(map[uint64]struct{})
members = make(map[uint64]int)
time.Sleep(10 * TickDuration)
time.Sleep(10 * config.TickDuration)
}
for l := range leaders {
if index, ok := members[l]; ok {
Expand Down
24 changes: 12 additions & 12 deletions tests/framework/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
lockpb "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc"
"go.etcd.io/etcd/server/v3/verify"
framecfg "go.etcd.io/etcd/tests/v3/framework/config"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"

Expand All @@ -70,7 +71,6 @@ import (
const (
// RequestWaitTimeout is the time duration to wait for a request to go through or detect leader loss.
RequestWaitTimeout = 5 * time.Second
TickDuration = 10 * time.Millisecond
RequestTimeout = 20 * time.Second

ClusterName = "etcd"
Expand Down Expand Up @@ -363,7 +363,7 @@ func (c *Cluster) RemoveMember(t testutil.TB, cc *clientv3.Client, id uint64) er
// 1s stop delay + election timeout + 1s disk and network delay + connection write timeout
// TODO: remove connection write timeout by selecting on http response closeNotifier
// blocking on https://github.com/golang/go/issues/9524
case <-time.After(time.Second + time.Duration(ElectionTicks)*TickDuration + time.Second + rafthttp.ConnWriteTimeout):
case <-time.After(time.Second + time.Duration(ElectionTicks)*framecfg.TickDuration + time.Second + rafthttp.ConnWriteTimeout):
t.Fatalf("failed to remove member %s in time", m.Server.MemberId())
}
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func (c *Cluster) WaitMembersMatch(t testutil.TB, membs []*pb.Member) {
if isMembersEqual(resp.Members, membs) {
break
}
time.Sleep(TickDuration)
time.Sleep(framecfg.TickDuration)
}
}
}
Expand Down Expand Up @@ -445,7 +445,7 @@ func (c *Cluster) waitMembersForLeader(ctx context.Context, t testing.TB, membs
}
// ensure leader is up via linearizable get
for {
ctx, cancel := context.WithTimeout(ctx, 10*TickDuration+time.Second)
ctx, cancel := context.WithTimeout(ctx, 10*framecfg.TickDuration+time.Second)
_, err := cc.Get(ctx, "0")
cancel()
if err == nil || strings.Contains(err.Error(), "Key not found") {
Expand All @@ -463,7 +463,7 @@ func (c *Cluster) waitMembersForLeader(ctx context.Context, t testing.TB, membs
}
if lead != 0 && lead != m.Server.Lead() {
lead = 0
time.Sleep(10 * TickDuration)
time.Sleep(10 * framecfg.TickDuration)
break
}
lead = m.Server.Lead()
Expand Down Expand Up @@ -496,7 +496,7 @@ func (c *Cluster) WaitMembersNoLeader(membs []*Member) {
}
if m.Server.Lead() != 0 {
noLeader = false
time.Sleep(10 * TickDuration)
time.Sleep(10 * framecfg.TickDuration)
break
}
}
Expand All @@ -509,7 +509,7 @@ func (c *Cluster) waitVersion() {
if m.Server.ClusterVersion() != nil {
break
}
time.Sleep(TickDuration)
time.Sleep(framecfg.TickDuration)
}
}
}
Expand Down Expand Up @@ -655,7 +655,7 @@ func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member {
}
m.ElectionTicks = ElectionTicks
m.InitialElectionTickAdvance = true
m.TickMs = uint(TickDuration / time.Millisecond)
m.TickMs = uint(framecfg.TickDuration / time.Millisecond)
m.QuotaBackendBytes = mcfg.QuotaBackendBytes
m.MaxTxnOps = mcfg.MaxTxnOps
if m.MaxTxnOps == 0 {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func (m *Member) RecordedRequests() []grpc_testing.RequestInfo {
func (m *Member) WaitOK(t testutil.TB) {
m.WaitStarted(t)
for m.Server.Leader() == 0 {
time.Sleep(TickDuration)
time.Sleep(framecfg.TickDuration)
}
}

Expand All @@ -1088,7 +1088,7 @@ func (m *Member) WaitStarted(t testutil.TB) {
ctx, cancel := context.WithTimeout(context.Background(), RequestTimeout)
_, err := m.Client.Get(ctx, "/", clientv3.WithSerializable())
if err != nil {
time.Sleep(TickDuration)
time.Sleep(framecfg.TickDuration)
continue
}
cancel()
Expand All @@ -1106,7 +1106,7 @@ func WaitClientV3(t testutil.TB, kv clientv3.KV) {
if err == nil {
return
}
time.Sleep(TickDuration)
time.Sleep(framecfg.TickDuration)
}
if err != nil {
t.Fatalf("timed out waiting for client: %v", err)
Expand Down Expand Up @@ -1604,7 +1604,7 @@ func (c *Cluster) waitMembersMatch(t testutil.TB) {
return
}

time.Sleep(TickDuration)
time.Sleep(framecfg.TickDuration)
}
}

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/integration"
)

Expand Down Expand Up @@ -294,7 +295,7 @@ func TestIssue3699(t *testing.T) {
// do not restart the killed member immediately.
// the member will advance its election timeout after restart,
// so it will have a better chance to become the leader again.
time.Sleep(time.Duration(integration.ElectionTicks * int(integration.TickDuration)))
time.Sleep(time.Duration(integration.ElectionTicks * int(config.TickDuration)))
c.Members[leaderID].Restart(t)
leaderID = c.WaitMembersForLeader(t, c.Members)
}
Expand Down Expand Up @@ -391,7 +392,7 @@ func TestRejectUnhealthyRemove(t *testing.T) {
}

// member stopped after launch; wait for missing heartbeats
time.Sleep(time.Duration(integration.ElectionTicks * int(integration.TickDuration)))
time.Sleep(time.Duration(integration.ElectionTicks * int(config.TickDuration)))

// permit remove dead member since (3,2) - (0,1) => (3,1) has quorum
if err = c.RemoveMember(t, c.Members[2].Client, uint64(c.Members[0].Server.MemberId())); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/integration"

"google.golang.org/grpc"
Expand Down Expand Up @@ -1817,7 +1818,7 @@ func TestGRPCRequireLeader(t *testing.T) {
defer client.Close()

// wait for election timeout, then member[0] will not have a leader.
time.Sleep(time.Duration(3*integration.ElectionTicks) * integration.TickDuration)
time.Sleep(time.Duration(3*integration.ElectionTicks) * config.TickDuration)

md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader)
ctx := metadata.NewOutgoingContext(context.Background(), md)
Expand Down Expand Up @@ -1870,7 +1871,7 @@ func TestGRPCStreamRequireLeader(t *testing.T) {
clus.Members[2].Restart(t)

clus.WaitMembersForLeader(t, clus.Members)
time.Sleep(time.Duration(2*integration.ElectionTicks) * integration.TickDuration)
time.Sleep(time.Duration(2*integration.ElectionTicks) * config.TickDuration)

// new stream should also be OK now after we restarted the other members
wStream, err = wAPI.Watch(ctx)
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.etcd.io/etcd/api/v3/mvccpb"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/pkg/v3/testutil"
framecfg "go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/integration"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -391,7 +392,7 @@ func TestV3LeaseCheckpoint(t *testing.T) {
leaderId := clus.WaitLeader(t)
leader := clus.Members[leaderId]
leader.Stop(t)
time.Sleep(time.Duration(3*integration.ElectionTicks) * integration.TickDuration)
time.Sleep(time.Duration(3*integration.ElectionTicks) * framecfg.TickDuration)
leader.Restart(t)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/v3_watch_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (
"time"

pb "go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/integration"
)

// MustFetchNotEmptyMetric attempts to fetch given 'metric' from 'member',
// waiting for not-empty value or 'timeout'.
func MustFetchNotEmptyMetric(tb testing.TB, member *integration.Member, metric string, timeout <-chan time.Time) string {
metricValue := ""
tick := time.Tick(integration.TickDuration)
tick := time.Tick(config.TickDuration)
for metricValue == "" {
tb.Logf("Waiting for metric: %v", metric)
select {
Expand Down

0 comments on commit a1405e9

Please sign in to comment.