Skip to content

Commit af83870

Browse files
committed
Add more logging for failed tests
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent b9ac7fb commit af83870

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

agent/agent_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,7 @@ func TestAgent_WriteVSCodeConfigs(t *testing.T) {
17971797
}
17981798

17991799
func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) (*ptytest.PTYCmd, pty.Process) {
1800+
logger := slogtest.Make(t, nil).Named("testsetup").Leveled(slog.LevelDebug)
18001801
//nolint:dogsled
18011802
agentConn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
18021803
listener, err := net.Listen("tcp", "127.0.0.1:0")
@@ -1807,16 +1808,20 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) (*pt
18071808
for {
18081809
conn, err := listener.Accept()
18091810
if err != nil {
1811+
logger.Debug(context.Background(), "error listening", slog.Error(err))
18101812
return
18111813
}
1814+
logger.Debug(context.Background(), "got local TCP connection")
18121815

18131816
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
18141817
ssh, err := agentConn.SSH(ctx)
18151818
cancel()
18161819
if err != nil {
1820+
logger.Debug(context.Background(), "failed to connect to agent SSH")
18171821
_ = conn.Close()
18181822
return
18191823
}
1824+
logger.Debug(context.Background(), "got SSH connection to agent")
18201825
waitGroup.Add(1)
18211826
go func() {
18221827
agentssh.Bicopy(context.Background(), conn, ssh)

tailnet/conn.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ var unixEpoch = time.Unix(0, 0)
588588
// the Wireguard layer. It's the callers responsibility to provide a timeout, otherwise this function will block
589589
// forever.
590590
func (c *Conn) AwaitReachable(ctx context.Context, ip netip.Addr) bool {
591+
logger := c.logger.With(slog.F("ip", ip))
591592
rightAway := make(chan struct{}, 1)
592593
rightAway <- struct{}{}
593594
tkr := time.NewTicker(50 * time.Millisecond)
@@ -603,7 +604,7 @@ func (c *Conn) AwaitReachable(ctx context.Context, ip netip.Addr) bool {
603604

604605
nKeys := c.getNodeKeysForIP(ip)
605606
if len(nKeys) == 0 {
606-
c.logger.Debug(ctx, "missing node(s) for IP", slog.F("ip", ip.String()))
607+
logger.Debug(ctx, "missing node(s) for IP", slog.F("ip", ip.String()))
607608
continue
608609
}
609610
s := c.Status()
@@ -613,9 +614,13 @@ func (c *Conn) AwaitReachable(ctx context.Context, ip netip.Addr) bool {
613614
c.logger.Debug(ctx, "missing status for node", slog.F("node", nKey.ShortString()))
614615
continue
615616
}
617+
logger.Debug(ctx, "checking peer for handshake",
618+
slog.F("peer", ps.PublicKey.ShortString()), slog.F("last_handshake", ps.LastHandshake))
616619
// Note that wireguard initializes the last handshake to the Unix Epoch until there is at least one
617620
// handshake
618621
if ps.LastHandshake.After(unixEpoch) {
622+
//nolint: gocritic
623+
logger.Debug(ctx, "IP is now reachable", slog.F("peer", ps.PublicKey.ShortString()))
619624
return true
620625
}
621626
}

0 commit comments

Comments
 (0)