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