Skip to content

Commit

Permalink
Merge pull request etcd-io#17427 from ivanvc/release-3.5-implement-et…
Browse files Browse the repository at this point in the history
…cd-process-go-fail-client-timeout

[3.5] Implement etcd process go fail client timeout
  • Loading branch information
ahrtr authored Feb 15, 2024
2 parents 3b99fee + 1115eb1 commit b795a8f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
44 changes: 23 additions & 21 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ type EtcdProcessCluster struct {
}

type EtcdProcessClusterConfig struct {
ExecPath string
DataDirPath string
KeepDataDir bool
GoFailEnabled bool
PeerProxy bool
EnvVars map[string]string
ExecPath string
DataDirPath string
KeepDataDir bool
GoFailEnabled bool
GoFailClientTimeout time.Duration
PeerProxy bool
EnvVars map[string]string

ClusterSize int

Expand Down Expand Up @@ -400,21 +401,22 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []*
}

etcdCfgs[i] = &EtcdServerProcessConfig{
lg: lg,
ExecPath: cfg.ExecPath,
Args: args,
EnvVars: envVars,
TlsArgs: cfg.TlsArgs(),
DataDirPath: dataDirPath,
KeepDataDir: cfg.KeepDataDir,
Name: name,
Purl: peerAdvertiseUrl,
Acurl: curl,
Murl: murl,
InitialToken: cfg.InitialToken,
ClientHttpUrl: clientHttpUrl,
GoFailPort: gofailPort,
Proxy: proxyCfg,
lg: lg,
ExecPath: cfg.ExecPath,
Args: args,
EnvVars: envVars,
TlsArgs: cfg.TlsArgs(),
DataDirPath: dataDirPath,
KeepDataDir: cfg.KeepDataDir,
Name: name,
Purl: peerAdvertiseUrl,
Acurl: curl,
Murl: murl,
InitialToken: cfg.InitialToken,
ClientHttpUrl: clientHttpUrl,
GoFailPort: gofailPort,
GoFailClientTimeout: cfg.GoFailClientTimeout,
Proxy: proxyCfg,
}
}

Expand Down
31 changes: 22 additions & 9 deletions tests/framework/e2e/etcd_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ type EtcdServerProcessConfig struct {
Murl string
ClientHttpUrl string

InitialToken string
InitialCluster string
GoFailPort int
Proxy *proxy.ServerConfig
InitialToken string
InitialCluster string
GoFailPort int
GoFailClientTimeout time.Duration
Proxy *proxy.ServerConfig
}

func NewEtcdServerProcess(cfg *EtcdServerProcessConfig) (*EtcdServerProcess, error) {
Expand All @@ -111,7 +112,10 @@ func NewEtcdServerProcess(cfg *EtcdServerProcessConfig) (*EtcdServerProcess, err
}
ep := &EtcdServerProcess{cfg: cfg, donec: make(chan struct{})}
if cfg.GoFailPort != 0 {
ep.failpoints = &BinaryFailpoints{member: ep}
ep.failpoints = &BinaryFailpoints{
member: ep,
clientTimeout: cfg.GoFailClientTimeout,
}
}
return ep, nil
}
Expand Down Expand Up @@ -258,6 +262,7 @@ func (ep *EtcdServerProcess) Etcdctl(connType ClientConnType, isAutoTLS, v2 bool
type BinaryFailpoints struct {
member EtcdProcess
availableCache map[string]string
clientTimeout time.Duration
}

func (f *BinaryFailpoints) SetupEnv(failpoint, payload string) error {
Expand All @@ -279,6 +284,12 @@ func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload str
if err != nil {
return err
}
httpClient := http.Client{
Timeout: 1 * time.Second,
}
if f.clientTimeout != 0 {
httpClient.Timeout = f.clientTimeout
}
resp, err := httpClient.Do(r)
if err != nil {
return err
Expand All @@ -301,6 +312,12 @@ func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string)
if err != nil {
return err
}
httpClient := http.Client{
Timeout: 1 * time.Second,
}
if f.clientTimeout != 0 {
httpClient.Timeout = f.clientTimeout
}
resp, err := httpClient.Do(r)
if err != nil {
return err
Expand All @@ -312,10 +329,6 @@ func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string)
return nil
}

var httpClient = http.Client{
Timeout: 1 * time.Second,
}

func (f *BinaryFailpoints) Enabled() bool {
_, err := failpoints(f.member)
if err != nil {
Expand Down

0 comments on commit b795a8f

Please sign in to comment.