Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Refresh client connections when they are no longer useful. #12941

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions test/pkg/integration/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ func (c *ComponentAPI) WorkspaceManager() (wsmanapi.WorkspaceManagerClient, erro
return c.wsmanStatus.Client, nil
}

func (c *ComponentAPI) ClearWorkspaceManagerClientCache() {
c.wsmanStatus.Client = nil
c.wsmanStatus.Port = 0
}

// BlobService provides access to the blob service of the content service
func (c *ComponentAPI) BlobService() (csapi.BlobServiceClient, error) {
if c.contentServiceStatus.BlobServiceClient != nil {
Expand Down Expand Up @@ -739,6 +744,11 @@ func (c *ComponentAPI) BlobService() (csapi.BlobServiceClient, error) {
return c.contentServiceStatus.BlobServiceClient, nil
}

func (c *ComponentAPI) ClearBlobServiceClientCache() {
c.contentServiceStatus.BlobServiceClient = nil
c.contentServiceStatus.Port = 0
}

type dbOpts struct {
Database string
}
Expand Down Expand Up @@ -1040,6 +1050,11 @@ func (c *ComponentAPI) ImageBuilder(opts ...APIImageBuilderOpt) (imgbldr.ImageBu
return c.imgbldStatus.Client, nil
}

func (c *ComponentAPI) ClearImageBuilderClientCache() {
c.imgbldStatus.Client = nil
c.imgbldStatus.Port = 0
}

// ContentService groups content service interfaces for convenience
type ContentService interface {
csapi.ContentServiceClient
Expand Down Expand Up @@ -1089,6 +1104,11 @@ func (c *ComponentAPI) ContentService() (ContentService, error) {
return c.contentServiceStatus.ContentService, nil
}

func (c *ComponentAPI) ClearContentServiceClientCache() {
c.contentServiceStatus.ContentService = nil
c.contentServiceStatus.Port = 0
}

func (c *ComponentAPI) Done(t *testing.T) {
// Much "defer", we run the closer in reversed order. This way, we can
// append to this list quite naturally, and still break things down in
Expand Down
15 changes: 15 additions & 0 deletions test/pkg/integration/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func LaunchWorkspaceDirectly(t *testing.T, ctx context.Context, api *ComponentAP
for {
workspaceImage, err = resolveOrBuildImage(ctx, api, options.BaseImage)
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
api.ClearImageBuilderClientCache()
time.Sleep(5 * time.Second)
continue
} else if err != nil {
Expand Down Expand Up @@ -290,6 +291,7 @@ func stopWsF(t *testing.T, instanceID string, api *ComponentAPI) stopWorkspaceFu
t.Logf("attemp to delete the workspace: %s", instanceID)
err = DeleteWorkspace(sctx, api, instanceID)
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
api.ClearWorkspaceManagerClientCache()
t.Logf("got %v when deleting workspace", st)
time.Sleep(5 * time.Second)
continue
Expand Down Expand Up @@ -323,6 +325,7 @@ func stopWsF(t *testing.T, instanceID string, api *ComponentAPI) stopWorkspaceFu
t.Logf("waiting for stopping the workspace: %s", instanceID)
lastStatus, err := WaitForWorkspaceStop(sctx, api, instanceID)
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
api.ClearWorkspaceManagerClientCache()
t.Logf("got %v during waiting for stopping the workspace", st)
time.Sleep(5 * time.Second)
continue
Expand Down Expand Up @@ -389,6 +392,18 @@ func WaitForWorkspaceStart(ctx context.Context, instanceID string, api *Componen
resp, err := sub.Recv()
if err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
sub.CloseSend()
api.ClearWorkspaceManagerClientCache()
wsman, err := api.WorkspaceManager()
if err != nil {
errStatus <- xerrors.Errorf("cannot listen for workspace updates: %w", err)
return
}
sub, err = wsman.Subscribe(ctx, &wsmanapi.SubscribeRequest{})
if err != nil {
errStatus <- xerrors.Errorf("cannot listen for workspace updates: %w", err)
return
}
continue
}
errStatus <- xerrors.Errorf("workspace update error: %q", err)
Expand Down