diff --git a/packer/rpc/client_test.go b/packer/rpc/client_test.go index 1f9b930a7..09976aabb 100644 --- a/packer/rpc/client_test.go +++ b/packer/rpc/client_test.go @@ -1,9 +1,33 @@ package rpc import ( + "net" "testing" ) func testClient(t *testing.T, server *Server) *Client { - return nil + l, err := net.Listen("tcp", ":0") + if err != nil { + t.Fatalf("err: %s", err) + } + + go func() { + conn, err := l.Accept() + if err != nil { + t.Fatalf("err: %s", err) + } + server.ServeConn(conn) + }() + + clientConn, err := net.Dial("tcp", l.Addr().String()) + if err != nil { + t.Fatalf("err: %s", err) + } + + client, err := NewClient(clientConn) + if err != nil { + t.Fatalf("err: %s", err) + } + + return client } diff --git a/packer/rpc/server_new.go b/packer/rpc/server_new.go index 4fcda1f00..9ad95b6ce 100644 --- a/packer/rpc/server_new.go +++ b/packer/rpc/server_new.go @@ -34,8 +34,8 @@ func (s *Server) ServeConn(conn io.ReadWriteCloser) { mux := NewMuxConn(conn) defer mux.Close() - // Get stream ID 0, which we always use as the stream for serving - // our RPC server on. + // Accept a connection on stream ID 0, which is always used for + // normal client to server connections. stream, err := mux.Accept(0) if err != nil { log.Printf("[ERR] Error retrieving stream for serving: %s", err)