Skip to content

Commit

Permalink
Fix race condition in tests due to use of globals in configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksander Mistewicz <[email protected]>
  • Loading branch information
AwesomePatrol committed Dec 12, 2024
1 parent 46570f6 commit 2febbd8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ func NewConfig() *Config {
}

func (cfg *Config) AddFlags(fs *flag.FlagSet) {
cfg.AddFlagsWithoutGlobals(fs)

// raft connection timeouts
fs.DurationVar(&rafthttp.ConnReadTimeout, "raft-read-timeout", rafthttp.DefaultConnReadTimeout, "Read timeout set on each rafthttp connection")
fs.DurationVar(&rafthttp.ConnWriteTimeout, "raft-write-timeout", rafthttp.DefaultConnWriteTimeout, "Write timeout set on each rafthttp connection")
}

func (cfg *Config) AddFlagsWithoutGlobals(fs *flag.FlagSet) {
// member
fs.StringVar(&cfg.Dir, "data-dir", cfg.Dir, "Path to the data directory.")
fs.StringVar(&cfg.WalDir, "wal-dir", cfg.WalDir, "Path to the dedicated wal directory.")
Expand Down Expand Up @@ -640,10 +648,6 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {

fs.Var(flags.NewUint32Value(cfg.MaxConcurrentStreams), "max-concurrent-streams", "Maximum concurrent streams that each client can open at a time.")

// raft connection timeouts
fs.DurationVar(&rafthttp.ConnReadTimeout, "raft-read-timeout", rafthttp.DefaultConnReadTimeout, "Read timeout set on each rafthttp connection")
fs.DurationVar(&rafthttp.ConnWriteTimeout, "raft-write-timeout", rafthttp.DefaultConnWriteTimeout, "Write timeout set on each rafthttp connection")

// clustering
fs.Var(
flags.NewUniqueURLsWithExceptions(DefaultInitialAdvertisePeerURLs, ""),
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in

func values(cfg embed.Config) map[string]string {
fs := flag.NewFlagSet("etcd", flag.ContinueOnError)
cfg.AddFlags(fs)
cfg.AddFlagsWithoutGlobals(fs)
values := map[string]string{}
fs.VisitAll(func(f *flag.Flag) {
value := f.Value.String()
Expand Down

0 comments on commit 2febbd8

Please sign in to comment.