test: change channel operations to avoid potential goroutine leaks

In these unit tests, goroutines may leak if certain branches are chosen. This commit edits channel operations and buffer sizes, so no matter what branch is chosen, the test will end correctly. This commit doesn't change the semantics of unit tests.
This commit is contained in:
lzhfromustc
2020-12-09 22:23:21 -05:00
parent ca866c0242
commit f2a912a4e6
6 changed files with 20 additions and 18 deletions

View File

@@ -22,14 +22,14 @@ import (
func TestReadWriteTimeoutDialer(t *testing.T) {
stop := make(chan struct{})
defer func() {
stop <- struct{}{}
}()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("unexpected listen error: %v", err)
}
defer func() {
stop <- struct{}{}
}()
ts := testBlockingServer{ln, 2, stop}
go ts.Start(t)