newServer creates multiple servers with the given bootstrap content. Each server gets a different hostname, in the format of <hostnamePrefix>-<index>.
(hostnamePrefix, binaryPath, bootstrap string, logger io.Writer, count int)
| 138 | // Each server gets a different hostname, in the format of |
| 139 | // <hostnamePrefix>-<index>. |
| 140 | func newServers(hostnamePrefix, binaryPath, bootstrap string, logger io.Writer, count int) (_ []*server, err error) { |
| 141 | var ret []*server |
| 142 | defer func() { |
| 143 | if err != nil { |
| 144 | for _, s := range ret { |
| 145 | s.stop() |
| 146 | } |
| 147 | } |
| 148 | }() |
| 149 | for i := 0; i < count; i++ { |
| 150 | port := serverPort + i |
| 151 | cmd := cmd( |
| 152 | binaryPath, |
| 153 | logger, |
| 154 | []string{ |
| 155 | fmt.Sprintf("--port=%d", port), |
| 156 | fmt.Sprintf("--host_name_override=%s-%d", hostnamePrefix, i), |
| 157 | }, |
| 158 | []string{ |
| 159 | "GRPC_GO_LOG_VERBOSITY_LEVEL=99", |
| 160 | "GRPC_GO_LOG_SEVERITY_LEVEL=info", |
| 161 | "GRPC_XDS_BOOTSTRAP_CONFIG=" + bootstrap, // The bootstrap content doesn't need to be quoted., |
| 162 | }, |
| 163 | ) |
| 164 | cmd.Start() |
| 165 | ret = append(ret, &server{cmd: cmd, port: port}) |
| 166 | } |
| 167 | return ret, nil |
| 168 | } |
| 169 | |
| 170 | func (s *server) stop() { |
| 171 | s.cmd.Process.Kill() |