Skip to content

fix: Close connections in agent tests #3196

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

Merged
merged 3 commits into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ func TestAgent(t *testing.T) {
localPort := tcpAddr.Port
done := make(chan struct{})
go func() {
defer close(done)
conn, err := local.Accept()
assert.NoError(t, err)
if !assert.NoError(t, err) {
return
}
_ = conn.Close()
close(done)
}()

err = setupSSHCommand(t, []string{"-L", fmt.Sprintf("%d:127.0.0.1:%d", randomPort, localPort)}, []string{"echo", "test"}).Start()
Expand Down Expand Up @@ -399,15 +401,18 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
go func() {
defer listener.Close()
for {
conn, err := listener.Accept()
if err != nil {
return
}
ssh, err := agentConn.SSH()
assert.NoError(t, err)
go io.Copy(conn, ssh)
go io.Copy(ssh, conn)
if !assert.NoError(t, err) {
_ = conn.Close()
return
}
go agent.Bicopy(context.Background(), conn, ssh)
}
}()
t.Cleanup(func() {
Expand Down