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,