From 4aadef188268857086189b24a131a0d132708b4d Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 12 Nov 2026 13:48:16 +0000 Subject: [PATCH] integration: share one workspace client across tests Same failure as #7507, on the Go integration test path: acc.WorkspaceTest built a client per test, so a timed-out OIDC discovery GET (not retried by the SDK) failed every test starting at that moment with "cannot configure default credentials". Co-authored-by: Isaac --- integration/internal/acc/workspace.go | 29 +++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/integration/internal/acc/workspace.go b/integration/internal/acc/workspace.go index 60804509124..af1e67010a2 100644 --- a/integration/internal/acc/workspace.go +++ b/integration/internal/acc/workspace.go @@ -2,6 +2,7 @@ package acc import ( "context" + "sync" "github.com/databricks/cli/internal/testutil" "github.com/databricks/databricks-sdk-go" @@ -19,14 +20,38 @@ type WorkspaceT struct { exec *compute.CommandExecutorV2 } +// sharedWorkspaceClientState holds the workspace client shared by all tests in +// the process. A client per test repeats OIDC endpoint discovery for every +// test, and the SDK does not retry that request on timeout. When the workspace +// is briefly slow, every test starting at that moment fails with "cannot +// configure default credentials". A shared client authenticates once and +// refreshes its token in the background. The SDK does not cache a failed +// authentication, so the next call on the shared client tries again. +var sharedWorkspaceClientState struct { + mu sync.Mutex + client *databricks.WorkspaceClient +} + +func sharedWorkspaceClient(t testutil.TestingT) *databricks.WorkspaceClient { + s := &sharedWorkspaceClientState + s.mu.Lock() + defer s.mu.Unlock() + + if s.client == nil { + w, err := databricks.NewWorkspaceClient() + require.NoError(t, err) + s.client = w + } + return s.client +} + func WorkspaceTest(t testutil.TestingT) (context.Context, *WorkspaceT) { t.Helper() testutil.LoadDebugEnvIfRunFromIDE(t, "workspace") t.Logf("CLOUD_ENV=%s", testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")) - w, err := databricks.NewWorkspaceClient() - require.NoError(t, err) + w := sharedWorkspaceClient(t) wt := &WorkspaceT{ TestingT: t,