From 1115eb1590a4fca8385c05fcbe3be5a21f6013ae Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Tue, 13 Feb 2024 14:29:32 -0800 Subject: [PATCH] tests/e2e: implement EtcdProcess GoFailClientTimeout Signed-off-by: Ivan Valdes --- tests/framework/e2e/cluster.go | 44 +++++++++++++++-------------- tests/framework/e2e/etcd_process.go | 31 ++++++++++++++------ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/tests/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index 126a6ee597e..97d58457155 100644 --- a/tests/framework/e2e/cluster.go +++ b/tests/framework/e2e/cluster.go @@ -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 @@ -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, } } diff --git a/tests/framework/e2e/etcd_process.go b/tests/framework/e2e/etcd_process.go index a741998c541..2f6650f19c7 100644 --- a/tests/framework/e2e/etcd_process.go +++ b/tests/framework/e2e/etcd_process.go @@ -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) { @@ -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 } @@ -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 { @@ -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 @@ -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 @@ -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 {