Skip to content

Commit 5a8e07d

Browse files
committed
test: Refresh a api client if it returns Unavailable
1 parent 5d44c77 commit 5a8e07d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/pkg/integration/workspace.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func LaunchWorkspaceDirectly(t *testing.T, ctx context.Context, api *ComponentAP
122122
for {
123123
workspaceImage, err = resolveOrBuildImage(ctx, api, options.BaseImage)
124124
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
125+
api.ClearImageBuilderClientCache()
125126
time.Sleep(5 * time.Second)
126127
continue
127128
} else if err != nil {
@@ -290,6 +291,7 @@ func stopWsF(t *testing.T, instanceID string, api *ComponentAPI) stopWorkspaceFu
290291
t.Logf("attemp to delete the workspace: %s", instanceID)
291292
err = DeleteWorkspace(sctx, api, instanceID)
292293
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
294+
api.ClearWorkspaceManagerClientCache()
293295
t.Logf("got %v when deleting workspace", st)
294296
time.Sleep(5 * time.Second)
295297
continue
@@ -323,6 +325,7 @@ func stopWsF(t *testing.T, instanceID string, api *ComponentAPI) stopWorkspaceFu
323325
t.Logf("waiting for stopping the workspace: %s", instanceID)
324326
lastStatus, err := WaitForWorkspaceStop(sctx, api, instanceID)
325327
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
328+
api.ClearWorkspaceManagerClientCache()
326329
t.Logf("got %v during waiting for stopping the workspace", st)
327330
time.Sleep(5 * time.Second)
328331
continue
@@ -389,6 +392,18 @@ func WaitForWorkspaceStart(ctx context.Context, instanceID string, api *Componen
389392
resp, err := sub.Recv()
390393
if err != nil {
391394
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
395+
sub.CloseSend()
396+
api.ClearWorkspaceManagerClientCache()
397+
wsman, err := api.WorkspaceManager()
398+
if err != nil {
399+
errStatus <- xerrors.Errorf("cannot listen for workspace updates: %w", err)
400+
return
401+
}
402+
sub, err = wsman.Subscribe(ctx, &wsmanapi.SubscribeRequest{})
403+
if err != nil {
404+
errStatus <- xerrors.Errorf("cannot listen for workspace updates: %w", err)
405+
return
406+
}
392407
continue
393408
}
394409
errStatus <- xerrors.Errorf("workspace update error: %q", err)

0 commit comments

Comments
 (0)