Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions integration/internal/acc/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acc

import (
"context"
"sync"

"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go"
Expand All @@ -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,
Expand Down
Loading