MCPcopy Create free account
hub / github.com/dadgar/onecache / buildConnectedNodes

Function buildConnectedNodes

onecache/test_util.go:43–83  ·  view source on GitHub ↗

Returns a list of Node's created using the passed configuration and joined with each other.

(configs []*NodeConfig)

Source from the content-addressed store, hash-verified

41
42// Returns a list of Node's created using the passed configuration and joined with each other.
43func 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
85func tearDownNodes(nodes []*Node) {
86 for _, n := range nodes {

Callers 1

connectedTestNodesFunction · 0.85

Calls 4

CreateFunction · 0.85
waitForResultFunction · 0.85
StartMethod · 0.80
JoinMethod · 0.80

Tested by

no test coverage detected