From f0ac331fdcf2870c039c85152a1774dfea173cdd Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Sat, 13 Jun 2026 00:39:59 +0200 Subject: [PATCH] [client/server] fix connect retry test for PermissionDenied short-circuit Commit 8841b950a made connectWithRetryRuns stop after a single login attempt on PermissionDenied, but TestConnectWithRetryRuns still asserted the loop retries 3+ times, so it failed with counter=1. Repurpose the test (now TestConnectStopsRetryOnPermissionDenied) to verify the loop stops after exactly one login on PermissionDenied, keeping the fast retry env config that would otherwise drive several attempts. Also redirect profile paths to a temp dir so it runs without root. --- client/server/server_test.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/client/server/server_test.go b/client/server/server_test.go index 66e0fcc4c..2146cfc7b 100644 --- a/client/server/server_test.go +++ b/client/server/server_test.go @@ -61,9 +61,25 @@ var ( } ) -// TestConnectWithRetryRuns checks that the connectWithRetry function runs and runs the retries according to the times specified via environment variables -// we will use a management server started via to simulate the server and capture the number of retries -func TestConnectWithRetryRuns(t *testing.T) { +// TestConnectStopsRetryOnPermissionDenied verifies connectWithRetryRuns stops after a single login +// attempt on PermissionDenied, despite the fast retry config that would otherwise drive several. +func TestConnectStopsRetryOnPermissionDenied(t *testing.T) { + // Redirect profile paths to a temp dir so the test does not need root. + tempDir := t.TempDir() + origDefaultProfileDir := profilemanager.DefaultConfigPathDir + origActiveProfileStatePath := profilemanager.ActiveProfileStatePath + origDefaultConfigPath := profilemanager.DefaultConfigPath + profilemanager.ConfigDirOverride = tempDir + profilemanager.DefaultConfigPathDir = tempDir + profilemanager.ActiveProfileStatePath = filepath.Join(tempDir, "active_profile.json") + profilemanager.DefaultConfigPath = filepath.Join(tempDir, "default.json") + t.Cleanup(func() { + profilemanager.DefaultConfigPathDir = origDefaultProfileDir + profilemanager.ActiveProfileStatePath = origActiveProfileStatePath + profilemanager.DefaultConfigPath = origDefaultConfigPath + profilemanager.ConfigDirOverride = "" + }) + // start the signal server _, signalAddr, err := startSignal(t) if err != nil { @@ -115,8 +131,8 @@ func TestConnectWithRetryRuns(t *testing.T) { t.Setenv(retryMultiplierVar, "1") s.connectWithRetryRuns(ctx, config, s.statusRecorder, nil, nil) - if counter < 3 { - t.Fatalf("expected counter > 2, got %d", counter) + if counter != 1 { + t.Fatalf("expected exactly 1 login attempt (PermissionDenied must stop the retry loop), got %d", counter) } }