2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-10 03:31:52 +08:00

Add TestClose

Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
This commit is contained in:
Abhilash Gnan 2021-01-14 23:05:11 +01:00 committed by Soheil Hassas Yeganeh
parent ce11cfdf3a
commit cdd3331e3e
2 changed files with 33 additions and 5 deletions

View File

@ -128,7 +128,7 @@ func runTestHTTPServer(errCh chan<- error, l net.Listener) {
mu.Unlock()
},
}
if err := s.Serve(l); err != ErrListenerClosed {
if err := s.Serve(l); err != ErrListenerClosed && err != ErrServerClosed {
errCh <- err
}
}
@ -218,7 +218,7 @@ func runTestRPCServer(errCh chan<- error, l net.Listener) {
for {
c, err := l.Accept()
if err != nil {
if err != ErrListenerClosed {
if err != ErrListenerClosed && err != ErrServerClosed {
errCh <- err
}
return
@ -651,7 +651,7 @@ func TestMultipleMatchers(t *testing.T) {
runTestHTTP1Client(t, l.Addr())
}
func TestClose(t *testing.T) {
func TestListenerClose(t *testing.T) {
defer leakCheck(t)()
errCh := make(chan error)
defer func() {
@ -685,7 +685,7 @@ func TestClose(t *testing.T) {
// Second connection either goes through or it is closed.
if _, err := anyl.Accept(); err != nil {
if err != ErrListenerClosed {
if err != ErrListenerClosed && err != ErrServerClosed {
t.Fatal(err)
}
// The error is either io.ErrClosedPipe or net.OpError wrapping
@ -696,6 +696,31 @@ func TestClose(t *testing.T) {
}
}
func TestClose(t *testing.T) {
defer leakCheck(t)()
errCh := make(chan error)
defer func() {
select {
case err := <-errCh:
t.Fatal(err)
default:
}
}()
l, cleanup := testListener(t)
defer cleanup()
muxl := New(l)
anyl := muxl.Match(Any())
go safeServe(errCh, muxl)
muxl.Close()
if _, err := anyl.Accept(); err != ErrServerClosed {
t.Fatal(err)
}
}
// Cribbed from google.golang.org/grpc/test/end2end_test.go.
// interestingGoroutines returns all goroutines we care about for the purpose

View File

@ -29,6 +29,7 @@ import (
"golang.org/x/net/websocket"
"github.com/soheilhy/cmux"
"google.golang.org/grpc/examples/helloworld/helloworld"
grpchello "google.golang.org/grpc/examples/helloworld/helloworld"
)
@ -86,7 +87,9 @@ func serveRPC(l net.Listener) {
}
}
type grpcServer struct{}
type grpcServer struct {
helloworld.UnimplementedGreeterServer
}
func (s *grpcServer) SayHello(ctx context.Context, in *grpchello.HelloRequest) (
*grpchello.HelloReply, error) {