@@ -40,17 +40,13 @@ import (
4040)
4141
4242// startEtcd starts an etcd subprocess, and waits for it to be ready.
43- func startEtcd (t * testing.T , port int ) (string , * exec.Cmd ) {
43+ func startEtcd (t * testing.T , clientPort , peerPort int ) (string , * exec.Cmd ) {
4444 // Create a temporary directory.
4545 dataDir := t .TempDir ()
4646
47- // Get our two ports to listen to.
48- if port == 0 {
49- port = testfiles .GoVtTopoEtcd2topoPort
50- }
5147 name := "vitess_unit_test"
52- clientAddr := fmt .Sprintf ("http://localhost:%v" , port )
53- peerAddr := fmt .Sprintf ("http://localhost:%v" , port + 1 )
48+ clientAddr := fmt .Sprintf ("http://localhost:%v" , clientPort )
49+ peerAddr := fmt .Sprintf ("http://localhost:%v" , peerPort )
5450 initialCluster := fmt .Sprintf ("%v=%v" , name , peerAddr )
5551
5652 cmd := exec .Command ("etcd" ,
@@ -104,11 +100,9 @@ func startEtcdWithTLS(t *testing.T) (string, *tlstest.ClientServerKeyPairs) {
104100 // Create a temporary directory.
105101 dataDir := t .TempDir ()
106102
107- // Get our two ports to listen to.
108- port := testfiles .GoVtTopoEtcd2topoPort
109103 name := "vitess_unit_test"
110- clientAddr := fmt .Sprintf ("https://localhost:%v" , port + 2 )
111- peerAddr := fmt .Sprintf ("https://localhost:%v" , port + 3 )
104+ clientAddr := fmt .Sprintf ("https://localhost:%v" , testfiles . GoVtTopoEtcd2topoTLSPort )
105+ peerAddr := fmt .Sprintf ("https://localhost:%v" , testfiles . GoVtTopoEtcd2topoTLSPeerPort )
112106 initialCluster := fmt .Sprintf ("%v=%v" , name , peerAddr )
113107
114108 certs := tlstest .CreateClientServerCertPairs (dataDir )
@@ -209,7 +203,7 @@ func TestEtcd2TLS(t *testing.T) {
209203
210204func TestEtcd2Topo (t * testing.T ) {
211205 // Start a single etcd in the background.
212- clientAddr , _ := startEtcd (t , 0 )
206+ clientAddr , _ := startEtcd (t , testfiles . GoVtTopoEtcd2topoPort , testfiles . GoVtTopoEtcd2topoPeerPort )
213207
214208 testIndex := 0
215209 newServer := func () * topo.Server {
@@ -253,16 +247,22 @@ func TestEtcd2TopoGetTabletsPartialResults(t *testing.T) {
253247 root := "/vitess"
254248 // Start three etcd instances in the background. One will serve the global topo data
255249 // while the other two will serve the cell topo data.
256- globalClientAddr , _ := startEtcd (t , 0 )
250+ globalClientAddr , _ := startEtcd (t , testfiles .GoVtTopoEtcd2topoPort , testfiles .GoVtTopoEtcd2topoPeerPort )
251+ cellPorts := [... ]struct {
252+ client , peer int
253+ }{
254+ {testfiles .GoVtTopoEtcd2topoCell1Port , testfiles .GoVtTopoEtcd2topoCell1PeerPort },
255+ {testfiles .GoVtTopoEtcd2topoCell2Port , testfiles .GoVtTopoEtcd2topoCell2PeerPort },
256+ }
257+ require .Equal (t , len (cells ), len (cellPorts ))
257258 cellClientAddrs := make ([]string , len (cells ))
258259 cellClientCmds := make ([]* exec.Cmd , len (cells ))
259260 cellTSs := make ([]* topo.Server , len (cells ))
260261 for i := range cells {
261- addr , cmd := startEtcd (t , testfiles . GoVtTopoEtcd2topoPort + ( i + 100 * i ) )
262+ addr , cmd := startEtcd (t , cellPorts [ i ]. client , cellPorts [ i ]. peer )
262263 cellClientAddrs [i ] = addr
263264 cellClientCmds [i ] = cmd
264265 }
265- require .Equal (t , len (cells ), len (cellTSs ))
266266
267267 // Setup the global topo server.
268268 globalTS , err := topo .OpenServer ("etcd2" , globalClientAddr , path .Join (root , topo .GlobalCell ))
@@ -353,7 +353,7 @@ func TestEtcd2TopoGetTabletsPartialResults(t *testing.T) {
353353// appropriate errors instead of panicking due to nil pointer dereference.
354354func TestEtcd2TopoServerClosed (t * testing.T ) {
355355 // Start a single etcd in the background.
356- clientAddr , _ := startEtcd (t , 0 )
356+ clientAddr , _ := startEtcd (t , testfiles . GoVtTopoEtcd2topoPort , testfiles . GoVtTopoEtcd2topoPeerPort )
357357
358358 testRoot := "/test-closed"
359359
0 commit comments