Change how cluster is started in tests

Instead of trying to start all the nodes with dynamic peer addresses
set, alwasy start one, then join the rest to this one.  The SetPeers
in the test may be causing leadership changes and sporadic failures.
pull/3670/head
Jason Wilder 2015-08-14 13:17:38 -06:00
parent 582e82879e
commit 0e59568825
1 changed files with 11 additions and 30 deletions

View File

@ -981,29 +981,15 @@ func NewConfig(path string) *meta.Config {
type Cluster struct { type Cluster struct {
path string path string
Stores []*Store Stores []*Store
n int
} }
// NewCluster returns a cluster of n stores within path. // NewCluster returns a cluster of n stores within path.
func NewCluster(path string, n int) *Cluster { func NewCluster(path string, n int) *Cluster {
c := &Cluster{path: path} c := &Cluster{path: path, n: n}
config := NewConfig(filepath.Join(path, strconv.Itoa(0)))
peers := []string{} s := NewStore(config)
if n > 1 { c.Stores = append(c.Stores, s)
// Construct a list of temporary peers.
peers := make([]string, n)
for i := range peers {
peers[i] = "127.0.0.1:0"
}
}
// Create new stores with temporary peers.
for i := 0; i < n; i++ {
config := NewConfig(filepath.Join(path, strconv.Itoa(i)))
config.Peers = peers
s := NewStore(config)
c.Stores = append(c.Stores, s)
}
return c return c
} }
@ -1045,19 +1031,14 @@ func (c *Cluster) Join() error {
// Open opens and initializes all stores in the cluster. // Open opens and initializes all stores in the cluster.
func (c *Cluster) Open() error { func (c *Cluster) Open() error {
if err := func() error { if err := func() error {
// Open each store and add to peer list.
peers := make([]string, len(c.Stores)) if err := c.Stores[0].Open(); err != nil {
for i, s := range c.Stores { return err
if err := s.Open(); err != nil {
return fmt.Errorf("open test store #%d: %s", i, err)
}
peers[i] = s.Addr.String()
} }
// Reset peers on all stores. for i := 1; i < c.n; i++ {
for _, s := range c.Stores { if err := c.Join(); err != nil {
if err := s.SetPeers(peers); err != nil { panic(fmt.Sprintf("failed to add new cluster node: %v", err))
return fmt.Errorf("set peers: %s", err)
} }
} }