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

Commit76d3a24

Browse files
committed
implement unit test to verify jetbrains functionality
1 parent2447970 commit76d3a24

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

‎agent/agent_test.go‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,41 @@ func TestAgent_Stats_Magic(t *testing.T) {
206206
remotePort:=tcpAddr.Port
207207
goechoOnce(t,rl)
208208

209-
sshClient:=setupAgentSSHClient(ctx,t)
209+
//nolint:dogsled
210+
conn,_,stats,_,_:=setupAgent(t, agentsdk.Manifest{},0)
211+
sshClient,err:=conn.SSHClient(ctx)
212+
require.NoError(t,err)
210213

211-
conn,err:=sshClient.Dial("tcp",fmt.Sprintf("127.0.0.1:%d",remotePort))
214+
tunneledConn,err:=sshClient.Dial("tcp",fmt.Sprintf("127.0.0.1:%d",remotePort))
212215
require.NoError(t,err)
213-
deferconn.Close()
214-
requireEcho(t,conn)
216+
t.Cleanup(func() {
217+
// always close on failure of test
218+
_=conn.Close()
219+
_=tunneledConn.Close()
220+
})
221+
222+
vars*agentsdk.Stats
223+
require.Eventuallyf(t,func()bool {
224+
varokbool
225+
s,ok=<-stats
226+
returnok&&s.ConnectionCount>0&&
227+
s.SessionCountJetBrains==1
228+
},testutil.WaitLong,testutil.IntervalFast,
229+
"never saw stats with conn open: %+v",s,
230+
)
231+
232+
// Manually closing the connection
233+
requireEcho(t,tunneledConn)
234+
_=rl.Close()
235+
236+
require.Eventuallyf(t,func()bool {
237+
varokbool
238+
s,ok=<-stats
239+
returnok&&s.ConnectionCount==0&&
240+
s.SessionCountJetBrains==0
241+
},testutil.WaitLong,testutil.IntervalFast,
242+
"never saw stats after conn closes: %+v",s,
243+
)
215244
})
216245
}
217246

‎agent/agentssh/jetbrainstrack.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package agentssh
22

33
import (
4+
"sync"
5+
46
"cdr.dev/slog"
57
"go.uber.org/atomic"
68
gossh"golang.org/x/crypto/ssh"
@@ -54,10 +56,13 @@ func (w *ChannelAcceptWatcher) Accept() (gossh.Channel, <-chan *gossh.Request, e
5456

5557
typeChannelOnClosestruct {
5658
gossh.Channel
59+
// once ensures close only decrements the counter once.
60+
// Because close can be called multiple times.
61+
once sync.Once
5762
donefunc()
5863
}
5964

6065
func (c*ChannelOnClose)Close()error {
61-
c.done()
66+
c.once.Do(c.done)
6267
returnc.Channel.Close()
6368
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp