Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix possible goroutine leaks in unit tests #4570

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/resolver/config_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ func (s) TestSafeConfigSelector(t *testing.T) {

retChan1 := make(chan *RPCConfig)
retChan2 := make(chan *RPCConfig)
defer close(retChan1)
defer close(retChan2)

one := 1
two := 2

resp1 := &RPCConfig{MethodConfig: serviceconfig.MethodConfig{MaxReqSize: &one}}
resp2 := &RPCConfig{MethodConfig: serviceconfig.MethodConfig{MaxReqSize: &two}}

cs1Called := make(chan struct{})
cs2Called := make(chan struct{})
cs1Called := make(chan struct{}, 1)
cs2Called := make(chan struct{}, 1)

cs1 := &fakeConfigSelector{
selectConfig: func(r RPCInfo) (*RPCConfig, error) {
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/httpfilter/fault/fault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (s) TestFaultInjection_MaxActiveFaults(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

streams := make(chan testpb.TestService_FullDuplexCallClient)
streams := make(chan testpb.TestService_FullDuplexCallClient, 5) // startStream() is called 5 times
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one, let's just change the Fatalf to an Errorf; I don't think it's a problem to continue running the rest of the test if an error happens.

startStream := func() {
str, err := client.FullDuplexCall(ctx)
if err != nil {
Expand All @@ -620,7 +620,7 @@ func (s) TestFaultInjection_MaxActiveFaults(t *testing.T) {
str := <-streams
str.CloseSend()
if _, err := str.Recv(); err != io.EOF {
t.Fatal("stream error:", err)
t.Error("stream error:", err)
}
}
releaseStream := func() {
Expand Down
6 changes: 5 additions & 1 deletion xds/internal/server/listener_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ type fakeListener struct {
}

func (fl *fakeListener) Accept() (net.Conn, error) {
cne := <-fl.acceptCh
cne, ok := <-fl.acceptCh
if !ok {
return nil, errors.New("a non-temporary error")
}
return cne.conn, cne.err
}

Expand Down Expand Up @@ -262,6 +265,7 @@ func (s) TestListenerWrapper_Accept(t *testing.T) {
}}, nil)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
defer close(lis.acceptCh)
select {
case <-ctx.Done():
t.Fatalf("timeout waiting for the ready channel to be written to after receipt of a good Listener update")
Expand Down