mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #17050 from ahrtr/gofail_client_timeout_20231201
Support setting http client timeout when enable/disable failpoint
This commit is contained in:
commit
9d18fb0c6c
@ -137,11 +137,12 @@ type EtcdProcessClusterConfig struct {
|
||||
|
||||
// Test config
|
||||
|
||||
KeepDataDir bool
|
||||
Logger *zap.Logger
|
||||
GoFailEnabled bool
|
||||
LazyFSEnabled bool
|
||||
PeerProxy bool
|
||||
KeepDataDir bool
|
||||
Logger *zap.Logger
|
||||
GoFailEnabled bool
|
||||
GoFailClientTimeout time.Duration
|
||||
LazyFSEnabled bool
|
||||
PeerProxy bool
|
||||
|
||||
// Process config
|
||||
|
||||
@ -326,6 +327,10 @@ func WithGoFailEnabled(enabled bool) EPClusterOption {
|
||||
return func(c *EtcdProcessClusterConfig) { c.GoFailEnabled = enabled }
|
||||
}
|
||||
|
||||
func WithGoFailClientTimeout(dur time.Duration) EPClusterOption {
|
||||
return func(c *EtcdProcessClusterConfig) { c.GoFailClientTimeout = dur }
|
||||
}
|
||||
|
||||
func WithLazyFSEnabled(enabled bool) EPClusterOption {
|
||||
return func(c *EtcdProcessClusterConfig) { c.LazyFSEnabled = enabled }
|
||||
}
|
||||
@ -609,23 +614,24 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
|
||||
}
|
||||
|
||||
return &EtcdServerProcessConfig{
|
||||
lg: cfg.Logger,
|
||||
ExecPath: execPath,
|
||||
Args: args,
|
||||
EnvVars: envVars,
|
||||
TlsArgs: cfg.TlsArgs(),
|
||||
Client: cfg.Client,
|
||||
DataDirPath: dataDirPath,
|
||||
KeepDataDir: cfg.KeepDataDir,
|
||||
Name: name,
|
||||
PeerURL: peerAdvertiseUrl,
|
||||
ClientURL: curl,
|
||||
ClientHTTPURL: clientHttpUrl,
|
||||
MetricsURL: murl,
|
||||
InitialToken: cfg.ServerConfig.InitialClusterToken,
|
||||
GoFailPort: gofailPort,
|
||||
Proxy: proxyCfg,
|
||||
LazyFSEnabled: cfg.LazyFSEnabled,
|
||||
lg: cfg.Logger,
|
||||
ExecPath: execPath,
|
||||
Args: args,
|
||||
EnvVars: envVars,
|
||||
TlsArgs: cfg.TlsArgs(),
|
||||
Client: cfg.Client,
|
||||
DataDirPath: dataDirPath,
|
||||
KeepDataDir: cfg.KeepDataDir,
|
||||
Name: name,
|
||||
PeerURL: peerAdvertiseUrl,
|
||||
ClientURL: curl,
|
||||
ClientHTTPURL: clientHttpUrl,
|
||||
MetricsURL: murl,
|
||||
InitialToken: cfg.ServerConfig.InitialClusterToken,
|
||||
GoFailPort: gofailPort,
|
||||
GoFailClientTimeout: cfg.GoFailClientTimeout,
|
||||
Proxy: proxyCfg,
|
||||
LazyFSEnabled: cfg.LazyFSEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,9 +95,10 @@ type EtcdServerProcessConfig struct {
|
||||
ClientHTTPURL string
|
||||
MetricsURL string
|
||||
|
||||
InitialToken string
|
||||
InitialCluster string
|
||||
GoFailPort int
|
||||
InitialToken string
|
||||
InitialCluster string
|
||||
GoFailPort int
|
||||
GoFailClientTimeout time.Duration
|
||||
|
||||
LazyFSEnabled bool
|
||||
Proxy *proxy.ServerConfig
|
||||
@ -117,7 +118,10 @@ func NewEtcdServerProcess(t testing.TB, cfg *EtcdServerProcessConfig) (*EtcdServ
|
||||
}
|
||||
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,
|
||||
}
|
||||
}
|
||||
if cfg.LazyFSEnabled {
|
||||
ep.lazyfs = newLazyFS(cfg.lg, cfg.DataDirPath, t)
|
||||
@ -337,6 +341,7 @@ func (ep *EtcdServerProcess) Failpoints() *BinaryFailpoints {
|
||||
type BinaryFailpoints struct {
|
||||
member EtcdProcess
|
||||
availableCache map[string]string
|
||||
clientTimeout time.Duration
|
||||
}
|
||||
|
||||
func (f *BinaryFailpoints) SetupEnv(failpoint, payload string) error {
|
||||
@ -358,6 +363,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
|
||||
@ -380,6 +391,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
|
||||
@ -391,10 +408,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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user