MCPcopy
hub / github.com/grpc/grpc-go / TestServerCredsDispatch

Method TestServerCredsDispatch

test/creds_test.go:520–547  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

518}
519
520func (s) TestServerCredsDispatch(t *testing.T) {
521 lis, err := net.Listen("tcp", "localhost:0")
522 if err != nil {
523 t.Fatal(err)
524 }
525 cred := &serverDispatchCred{
526 rawConnCh: make(chan net.Conn, 1),
527 }
528 s := grpc.NewServer(grpc.Creds(cred))
529 go s.Serve(lis)
530 defer s.Stop()
531
532 cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(cred))
533 if err != nil {
534 t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err)
535 }
536 defer cc.Close()
537 cc.Connect()
538
539 rawConn := cred.getRawConn()
540 // Give grpc a chance to see the error and potentially close the connection.
541 // And check that connection is not closed after that.
542 time.Sleep(100 * time.Millisecond)
543 // Check rawConn is not closed.
544 if n, err := rawConn.Write([]byte{0}); n <= 0 || err != nil {
545 t.Errorf("Read() = %v, %v; want n>0, <nil>", n, err)
546 }
547}

Callers

nothing calls this directly

Calls 15

getRawConnMethod · 0.95
NewServerFunction · 0.92
CredsFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
FatalMethod · 0.65
ServeMethod · 0.65
StopMethod · 0.65
StringMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
ConnectMethod · 0.65

Tested by

no test coverage detected