func TestGRPCServerWithPanicWrapper(t *testing.T) {
	r := rmemory.NewRegistry()
	b := bmemory.NewBroker()
	tr := tgrpc.NewTransport()
	s := gsrv.NewServer(
		server.Broker(b),
		server.Name("foo"),
		server.Registry(r),
		server.Transport(tr),
		server.WrapHandler(func(hf server.HandlerFunc) server.HandlerFunc {
			return func(ctx context.Context, req server.Request, rsp interface{}) error {
				panic("wrapper panic")
			}
		}),
	)
	h := &testServer{}
	pb.RegisterTestHandler(s, h)
	if err := s.Start(); err != nil {
		t.Fatalf("failed to start: %v", err)
	}
	services, err := r.GetService("foo")
	if err != nil || len(services) == 0 {
		t.Fatalf("failed to get service: %v # %d", err, len(services))
	}
	defer func() {
		if err := s.Stop(); err != nil {
			t.Fatalf("failed to stop: %v", err)
		}
	}()
	cc, err := grpc.Dial(s.Options().Address, grpc.WithInsecure())
	if err != nil {
		t.Fatalf("failed to dial server: %v", err)
	}
	rsp := pb.Response{}
	if err := cc.Invoke(context.Background(), "/test.Test/Call", &pb.Request{Name: "John"}, &rsp); err == nil {
		t.Fatal("this must return error, as wrapper should be panic")
	}
	rsp = pb.Response{}
	if err := cc.Invoke(context.Background(), "/test.Test/Call", &pb.Request{Name: "Panic"}, &rsp); err == nil {
		t.Fatal("this must return error, as wrapper and handler should be panic")
	}
}
TestGRPCServerWithPanicWrapper test grpc server with panic wrapper
gRPC server should not crash when wrapper crashed
package grpc_test
import (
	"context"
	"fmt"
	"testing"
	pberr "github.com/micro/micro/v3/proto/errors"
	bmemory "github.com/micro/micro/v3/service/broker/memory"
	"github.com/micro/micro/v3/service/client"
	gcli "github.com/micro/micro/v3/service/client/grpc"
	"github.com/micro/micro/v3/service/errors"
	tgrpc "github.com/micro/micro/v3/service/network/transport/grpc"
	rmemory "github.com/micro/micro/v3/service/registry/memory"
	"github.com/micro/micro/v3/service/router"
	rtreg "github.com/micro/micro/v3/service/router/registry"
	"github.com/micro/micro/v3/service/server"
	gsrv "github.com/micro/micro/v3/service/server/grpc"
	pb "github.com/micro/micro/v3/service/server/grpc/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/status"
)
type testServer struct {
	msgCount int
}
func (s *testServer) Handle(ctx context.Context, msg *pb.Request) error {
	s.msgCount++
	return nil
}
func (s *testServer) HandleError(ctx context.Context, msg *pb.Request) error {
	return fmt.Errorf("fake")
}
func (s *testServer) CallPcre(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
	if req.Name == "Error" {
		return &errors.Error{Id: "1", Code: 99, Detail: "detail"}
	}
	rsp.Msg = "Hello " + req.Name
	return nil
}
func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
	if req.Name == "Error" {
		return &errors.Error{Id: "1", Code: 99, Detail: "detail"}
	}
	rsp.Msg = "Hello " + req.Name
	return nil
}
func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
	if req.Name == "Error" {
		return &errors.Error{Id: "1", Code: 99, Detail: "detail"}
	}
	if req.Name == "Panic" {
		panic("handler panic")
	}
	rsp.Msg = "Hello " + req.Name
	return nil
}
func TestGRPCServer(t *testing.T) {
	r := rmemory.NewRegistry()
	b := bmemory.NewBroker()
	tr := tgrpc.NewTransport()
	rtr := rtreg.NewRouter(router.Registry(r))
	s := gsrv.NewServer(
		server.Broker(b),
		server.Name("foo"),
		server.Registry(r),
		server.Transport(tr),
	)
	c := gcli.NewClient(
		client.Router(rtr),
		client.Broker(b),
		client.Transport(tr),
	)
	ctx := context.TODO()
	h := &testServer{}
	pb.RegisterTestHandler(s, h)
	if err := s.Subscribe(s.NewSubscriber("test_topic", h.Handle)); err != nil {
		t.Fatal(err)
	}
	if err := s.Start(); err != nil {
		t.Fatalf("failed to start: %v", err)
	}
	services, err := r.GetService("foo")
	if err != nil || len(services) == 0 {
		t.Fatalf("failed to get service: %v # %d", err, len(services))
	}
	defer func() {
		if err := s.Stop(); err != nil {
			t.Fatalf("failed to stop: %v", err)
		}
	}()
	cnt := 4
	for i := 0; i < cnt; i++ {
		msg := c.NewMessage("test_topic", &pb.Request{Name: fmt.Sprintf("msg %d", i)})
		if err = c.Publish(ctx, msg); err != nil {
			t.Fatal(err)
		}
	}
	if h.msgCount != cnt {
		t.Fatalf("pub/sub not work, or invalid message count %d", h.msgCount)
	}
	cc, err := grpc.Dial(s.Options().Address, grpc.WithInsecure())
	if err != nil {
		t.Fatalf("failed to dial server: %v", err)
	}
	testMethods := []string{"/test.Test/Call", "/go.micro.test.Test/Call"}
	for _, method := range testMethods {
		rsp := pb.Response{}
		if err := cc.Invoke(context.Background(), method, &pb.Request{Name: "John"}, &rsp); err != nil {
			t.Fatalf("error calling server: %v", err)
		}
		if rsp.Msg != "Hello John" {
			t.Fatalf("Got unexpected response %v", rsp.Msg)
		}
	}
	rsp := pb.Response{}
	if err := cc.Invoke(context.Background(), "/test.Test/Call", &pb.Request{Name: "Error"}, &rsp); err != nil {
		st, ok := status.FromError(err)
		if !ok {
			t.Fatalf("invalid error received %#+v\n", err)
		}
		verr, ok := st.Details()[0].(*pberr.Error)
		if !ok {
			t.Fatalf("invalid error received %#+v\n", st.Details()[0])
		}
		if verr.Code != 99 && verr.Id != "1" && verr.Detail != "detail" {
			t.Fatalf("invalid error received %#+v\n", verr)
		}
	}
}