Returns a list of Node's created using the passed configuration and joined with each other.
(configs []*NodeConfig)
| 41 | |
| 42 | // Returns a list of Node's created using the passed configuration and joined with each other. |
| 43 | func buildConnectedNodes(configs []*NodeConfig) ([]*Node, error) { |
| 44 | nodes := make([]*Node, len(configs)) |
| 45 | for i, c := range configs { |
| 46 | n, err := Create(c) |
| 47 | if err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | |
| 51 | n.Start() |
| 52 | nodes[i] = n |
| 53 | } |
| 54 | |
| 55 | // Allow the nodes to setup. |
| 56 | time.Sleep(10 * time.Millisecond) |
| 57 | |
| 58 | if len(nodes) == 1 { |
| 59 | return nodes, nil |
| 60 | } |
| 61 | |
| 62 | // Create a slice containing the ports. |
| 63 | ip := make([]string, len(nodes)) |
| 64 | for i, n := range nodes { |
| 65 | ip[i] = fmt.Sprintf("127.0.0.1:%d", n.serf.LocalMember().Port) |
| 66 | } |
| 67 | |
| 68 | // Allow the nodes to join. |
| 69 | for _, node := range nodes { |
| 70 | node.Join(ip) |
| 71 | } |
| 72 | |
| 73 | waitForResult(func() (bool, error) { |
| 74 | for _, node := range nodes { |
| 75 | if len(node.nodes) != len(nodes) { |
| 76 | return false, nil |
| 77 | } |
| 78 | } |
| 79 | return true, nil |
| 80 | }, func(e error) {}) |
| 81 | |
| 82 | return nodes, nil |
| 83 | } |
| 84 | |
| 85 | func tearDownNodes(nodes []*Node) { |
| 86 | for _, n := range nodes { |
no test coverage detected