Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
cmd/swarm: simplify testCluster.StartNewNodes (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
janos authored and nonsense committed Sep 19, 2019
1 parent 1101eb9 commit d13ef0a
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions cmd/swarm/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,31 +170,18 @@ func (c *testCluster) Stop() {
}

func (c *testCluster) StartNewNodes(t *testing.T, size int) {
c.Nodes = make([]*testNode, 0, size)

errors := make(chan error, size)
nodes := make(chan *testNode, size)
c.Nodes = make([]*testNode, size)
for i := 0; i < size; i++ {
go func(nodeIndex int) {
dir := filepath.Join(c.TmpDir, fmt.Sprintf("swarm%02d", nodeIndex))
if err := os.Mkdir(dir, 0700); err != nil {
errors <- err
return
}

node := newTestNode(t, dir)
node.Name = fmt.Sprintf("swarm%02d", nodeIndex)
nodes <- node
}(i)
}
name := fmt.Sprintf("swarm%02d", i)

for i := 0; i < size; i++ {
select {
case node := <-nodes:
c.Nodes = append(c.Nodes, node)
case err := <-errors:
t.Error(err)
dir := filepath.Join(c.TmpDir, name)
if err := os.Mkdir(dir, 0777); err != nil {
t.Fatal(err)
}

node := newTestNode(t, dir)
node.Name = name
c.Nodes[i] = node
}

if t.Failed() {
Expand Down

0 comments on commit d13ef0a

Please sign in to comment.