diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..56f2d06 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,8 @@ +coverage: + status: + patch: + default: + target: 0% + project: + default: + target: 50% \ No newline at end of file diff --git a/pkg/grpc_proxy_server/server.go b/pkg/grpc_proxy_server/server.go index f7360ff..3a806fa 100644 --- a/pkg/grpc_proxy_server/server.go +++ b/pkg/grpc_proxy_server/server.go @@ -44,6 +44,12 @@ func New(config *config.Config, grpcServer *grpc_server.Server, services []servi return nil, err } + // Create a client connection to the gRPC server + ps.grpcConn, err = ps.createGrpcProxyConnection() + if err != nil { + return nil, err + } + // Create mux router to route HTTP requests in server mux := createGrpcProxyMuxServer() @@ -95,13 +101,6 @@ func createGrpcProxyMuxServer() *runtime.ServeMux { // Function runs gRPC proxy server on the [port] func (ps *Server) Run() error { - var err error - // Create a client connection to the gRPC server - ps.grpcConn, err = ps.createGrpcProxyConnection() - if err != nil { - return err - } - go func() { if err := ps.httpServer.ListenAndServe(); err != nil { ps.log.WithError(err).Fatal("Couldn't serve gRPC-Gateway server") diff --git a/pkg/grpc_proxy_server/server_test.go b/pkg/grpc_proxy_server/server_test.go index f86a05e..d5588ed 100644 --- a/pkg/grpc_proxy_server/server_test.go +++ b/pkg/grpc_proxy_server/server_test.go @@ -25,6 +25,8 @@ func TestNew(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, grpcs) + assert.NoError(t, grpcs.Run()) + s, err := grpc_proxy_server.New(c.Config, grpcs, []service.IServiceServer{}) assert.NoError(t, err) assert.NotNil(t, s) diff --git a/server.go b/server.go index 466b399..68f2613 100644 --- a/server.go +++ b/server.go @@ -56,20 +56,22 @@ func New(config *config.Config, externalServices []service.IServiceServer) (*Ser return nil, fmt.Errorf("couldn't create gRPC server. " + err.Error()) } - s.grpcProxyServer, err = grpc_proxy_server.New(s.Config, s.grpcServer, s.services) - if err != nil { - return nil, fmt.Errorf("couldn't create gRPC proxy server. " + err.Error()) - } - return s, nil } func (s *Server) Run() error { + var err error + // Run gRPC server before creating gRPC proxy to allow gRPC proxy dial connection with gRPC if err := s.grpcServer.Run(); err != nil { return fmt.Errorf("couldn't run gRPC server. " + err.Error()) } + // Init gRPC server proxy on run, because it can be inited only with working gRPC server + s.grpcProxyServer, err = grpc_proxy_server.New(s.Config, s.grpcServer, s.services) + if err != nil { + return fmt.Errorf("couldn't create gRPC proxy server. " + err.Error()) + } if err := s.grpcProxyServer.Run(); err != nil { return fmt.Errorf("couldn't run gRPC proxy server. " + err.Error()) }