Remove test-only methods from grpc package.

Move the test-only methods to a new internal package so as to not
pollute the godoc, and to prevent people from using them. (Packages
named internal or under internal are private, and enforced by the go
tool)
This commit is contained in:
Brad Fitzpatrick
2016-02-25 11:52:05 -08:00
parent 89f694edb4
commit 0f80f5b995
3 changed files with 65 additions and 13 deletions

View File

@ -52,6 +52,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/transport"
)
@ -705,10 +706,18 @@ func (s *Server) Stop() {
s.mu.Unlock()
}
// TestingCloseConns closes all exiting transports but keeps s.lis accepting new
// connections.
// This is only for tests and is subject to removal.
func (s *Server) TestingCloseConns() {
func init() {
internal.TestingCloseConns = func(arg interface{}) {
arg.(*Server).testingCloseConns()
}
internal.TestingUseHandlerImpl = func(arg interface{}) {
arg.(*Server).opts.useHandlerImpl = true
}
}
// testingCloseConns closes all existing transports but keeps s.lis
// accepting new connections.
func (s *Server) testingCloseConns() {
s.mu.Lock()
for c := range s.conns {
c.Close()
@ -717,13 +726,6 @@ func (s *Server) TestingCloseConns() {
s.mu.Unlock()
}
// TestingUseHandlerImpl enables the http.Handler-based server implementation.
// It must be called before Serve and requires TLS credentials.
// This is only for tests and is subject to removal.
func (s *Server) TestingUseHandlerImpl() {
s.opts.useHandlerImpl = true
}
// SendHeader sends header metadata. It may be called at most once from a unary
// RPC handler. The ctx is the RPC handler's Context or one derived from it.
func SendHeader(ctx context.Context, md metadata.MD) error {