Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit121c2bc

Browse files
authored
test(agent): Fix tests without cmd.Wait() (#7029)
1 parent2da0702 commit121c2bc

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎agent/agent_test.go‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,24 @@ func TestAgent_TCPLocalForwarding(t *testing.T) {
480480
}
481481
}()
482482

483+
pty:=ptytest.New(t)
484+
483485
cmd:=setupSSHCommand(t, []string{"-L",fmt.Sprintf("%d:127.0.0.1:%d",randomPort,remotePort)}, []string{"sleep","5"})
486+
cmd.Stdin=pty.Input()
487+
cmd.Stdout=pty.Output()
488+
cmd.Stderr=pty.Output()
484489
err=cmd.Start()
485490
require.NoError(t,err)
486491

492+
gofunc() {
493+
err:=cmd.Wait()
494+
select {
495+
case<-done:
496+
default:
497+
assert.NoError(t,err)
498+
}
499+
}()
500+
487501
require.Eventually(t,func()bool {
488502
conn,err:=net.Dial("tcp","127.0.0.1:"+strconv.Itoa(randomPort))
489503
iferr!=nil {
@@ -547,10 +561,24 @@ func TestAgent_TCPRemoteForwarding(t *testing.T) {
547561
}
548562
}()
549563

564+
pty:=ptytest.New(t)
565+
550566
cmd:=setupSSHCommand(t, []string{"-R",fmt.Sprintf("127.0.0.1:%d:127.0.0.1:%d",randomPort,localPort)}, []string{"sleep","5"})
567+
cmd.Stdin=pty.Input()
568+
cmd.Stdout=pty.Output()
569+
cmd.Stderr=pty.Output()
551570
err=cmd.Start()
552571
require.NoError(t,err)
553572

573+
gofunc() {
574+
err:=cmd.Wait()
575+
select {
576+
case<-done:
577+
default:
578+
assert.NoError(t,err)
579+
}
580+
}()
581+
554582
require.Eventually(t,func()bool {
555583
conn,err:=net.Dial("tcp",fmt.Sprintf("127.0.0.1:%d",randomPort))
556584
iferr!=nil {
@@ -612,10 +640,24 @@ func TestAgent_UnixLocalForwarding(t *testing.T) {
612640
}
613641
}()
614642

643+
pty:=ptytest.New(t)
644+
615645
cmd:=setupSSHCommand(t, []string{"-L",fmt.Sprintf("%s:%s",localSocketPath,remoteSocketPath)}, []string{"sleep","5"})
646+
cmd.Stdin=pty.Input()
647+
cmd.Stdout=pty.Output()
648+
cmd.Stderr=pty.Output()
616649
err=cmd.Start()
617650
require.NoError(t,err)
618651

652+
gofunc() {
653+
err:=cmd.Wait()
654+
select {
655+
case<-done:
656+
default:
657+
assert.NoError(t,err)
658+
}
659+
}()
660+
619661
require.Eventually(t,func()bool {
620662
_,err:=os.Stat(localSocketPath)
621663
returnerr==nil
@@ -670,10 +712,24 @@ func TestAgent_UnixRemoteForwarding(t *testing.T) {
670712
}
671713
}()
672714

715+
pty:=ptytest.New(t)
716+
673717
cmd:=setupSSHCommand(t, []string{"-R",fmt.Sprintf("%s:%s",remoteSocketPath,localSocketPath)}, []string{"sleep","5"})
718+
cmd.Stdin=pty.Input()
719+
cmd.Stdout=pty.Output()
720+
cmd.Stderr=pty.Output()
674721
err=cmd.Start()
675722
require.NoError(t,err)
676723

724+
gofunc() {
725+
err:=cmd.Wait()
726+
select {
727+
case<-done:
728+
default:
729+
assert.NoError(t,err)
730+
}
731+
}()
732+
677733
// It's possible that the socket is created but the server is not ready to
678734
// accept connections yet. We need to retry until we can connect.
679735
varconn net.Conn

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp