Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2447970

Browse files
committed
Add unit test to confirm tracking
1 parent c9a226f commit 2447970

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

agent/agent_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,28 @@ func TestAgent_Stats_Magic(t *testing.T) {
191191
err = session.Wait()
192192
require.NoError(t, err)
193193
})
194+
195+
// This test name being "Jetbrains" is required to be a certain string.
196+
// It must match the regex check in the agent for Jetbrains.
197+
t.Run("Jetbrains", func(t *testing.T) {
198+
t.Parallel()
199+
ctx := testutil.Context(t, testutil.WaitLong)
200+
201+
rl, err := net.Listen("tcp", "127.0.0.1:0")
202+
require.NoError(t, err)
203+
defer rl.Close()
204+
tcpAddr, valid := rl.Addr().(*net.TCPAddr)
205+
require.True(t, valid)
206+
remotePort := tcpAddr.Port
207+
go echoOnce(t, rl)
208+
209+
sshClient := setupAgentSSHClient(ctx, t)
210+
211+
conn, err := sshClient.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", remotePort))
212+
require.NoError(t, err)
213+
defer conn.Close()
214+
requireEcho(t, conn)
215+
})
194216
}
195217

196218
func TestAgent_SessionExec(t *testing.T) {

agent/agentssh/agentssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, extraEnv
295295
s.connCountVSCode.Add(1)
296296
defer s.connCountVSCode.Add(-1)
297297
case MagicSessionTypeJetBrains:
298-
s.connCountJetBrains.Add(1)
299-
defer s.connCountJetBrains.Add(-1)
298+
// Do nothing here because jetbrains launches hundreds of ssh sessions.
299+
// We instead track jetbrains in the single persistent tcp forwarding channel.
300300
case "":
301301
s.connCountSSHSession.Add(1)
302302
defer s.connCountSSHSession.Add(-1)

0 commit comments

Comments
 (0)