diff --git a/system_test/helpers.go b/system_test/helpers.go index 24d8bee1..60ff98de 100644 --- a/system_test/helpers.go +++ b/system_test/helpers.go @@ -366,10 +366,18 @@ func mustNewNode(enableSingle bool) *Node { } func mustNewNodeEncrypted(enableSingle, httpEncrypt, nodeEncrypt bool) *Node { - return mustNodeEncrypted(mustTempDir(), enableSingle, httpEncrypt, nodeEncrypt, "") + dir := mustTempDir() + var tn *tcp.Transport + if nodeEncrypt { + tn = mustNewOpenTLSTransport(x509.CertFile(dir), x509.CertFile(dir), "") + } else { + tn = mustNewOpenTransport("") + } + + return mustNodeEncrypted(dir, enableSingle, httpEncrypt, tn, "") } -func mustNodeEncrypted(dir string, enableSingle, httpEncrypt, nodeEncrypt bool, nodeID string) *Node { +func mustNodeEncrypted(dir string, enableSingle, httpEncrypt bool, tn store.Listener, nodeID string) *Node { nodeCertPath := x509.CertFile(dir) nodeKeyPath := x509.KeyFile(dir) httpCertPath := nodeCertPath @@ -385,17 +393,6 @@ func mustNodeEncrypted(dir string, enableSingle, httpEncrypt, nodeEncrypt bool, dbConf := store.NewDBConfig("", false) - var tn *tcp.Transport - if nodeEncrypt { - tn = tcp.NewTLSTransport(node.NodeCertPath, node.NodeCertPath, true) - } else { - tn = tcp.NewTransport() - } - - if err := tn.Open("localhost:0"); err != nil { - panic(err.Error()) - } - id := nodeID if id == "" { id = tn.Addr().String() @@ -449,6 +446,30 @@ func mustTempDir() string { return path } +func mustNewOpenTransport(addr string) *tcp.Transport { + if addr == "" { + addr = "localhost:0" + } + + tn := tcp.NewTransport() + if err := tn.Open(addr); err != nil { + panic(fmt.Sprintf("failed to open transport: %s", err)) + } + return tn +} + +func mustNewOpenTLSTransport(certFile, keyPath, addr string) *tcp.Transport { + if addr == "" { + addr = "localhost:0" + } + + tn := tcp.NewTLSTransport(certFile, keyPath, true) + if err := tn.Open(addr); err != nil { + panic(fmt.Sprintf("failed to open transport: %s", err)) + } + return tn +} + func mustParseDuration(d string) time.Duration { if dur, err := time.ParseDuration(d); err != nil { panic("failed to parse duration") diff --git a/system_test/single_node_test.go b/system_test/single_node_test.go index 3010b6aa..4c17c782 100644 --- a/system_test/single_node_test.go +++ b/system_test/single_node_test.go @@ -289,7 +289,10 @@ func Test_SingleNodeRestart(t *testing.T) { t.Fatalf("failed to copy node test directory: %s", err) } - node := mustNodeEncrypted(destdir, true, false, false, "node1") + tn := mustNewOpenTransport("") + defer tn.Close() + + node := mustNodeEncrypted(destdir, true, false, tn, "node1") defer node.Deprovision() if _, err := node.WaitForLeader(); err != nil { t.Fatal("node never became leader")