Skip to content

Commit 28b46b1

Browse files
committed
[integration-test] Wait for Theia service and endpoints to be cleaned up when stopping workspace
1 parent 3508a09 commit 28b46b1

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

test/pkg/integration/workspace.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"io"
11+
"strings"
1112
"sync"
1213
"time"
1314

@@ -413,13 +414,14 @@ func (it *Test) WaitForWorkspaceStop(instanceID string) (lastStatus *wsmanapi.Wo
413414
if desc != nil {
414415
switch desc.Status.Phase {
415416
case wsmanapi.WorkspacePhase_STOPPED:
416-
return desc.Status
417+
// ensure theia service is cleaned up
418+
lastStatus = desc.Status
417419
}
418420
}
419421

420422
select {
421423
case <-it.ctx.Done():
422-
it.t.Fatalf("cannot wait for workspace: %q", it.ctx.Err())
424+
it.t.Fatalf("cannot wait for workspace stop: %q", it.ctx.Err())
423425
return
424426
case <-done:
425427
}
@@ -432,16 +434,34 @@ func (it *Test) WaitForWorkspaceStop(instanceID string) (lastStatus *wsmanapi.Wo
432434
serviceGone bool
433435
k8s, ns = it.API().Kubernetes()
434436
)
437+
438+
// NOTE: this needs to be kept in sync with components/ws-manager/pkg/manager/manager.go:getTheiaServiceName()
439+
// TODO(rl) expose it?
440+
theiaName := fmt.Sprintf("ws-%s-theia", strings.TrimSpace(strings.ToLower(workspaceID)))
435441
for time.Since(start) < 1*time.Minute {
436-
_, err := k8s.CoreV1().Services(ns).Get(ctx, fmt.Sprintf("ws-%s-theia", workspaceID), v1.GetOptions{})
442+
_, err := k8s.CoreV1().Services(ns).Get(ctx, theiaName, v1.GetOptions{})
437443
if errors.IsNotFound(err) {
438444
serviceGone = true
439445
break
440446
}
441447
time.Sleep(200 * time.Millisecond)
442448
}
443449
if !serviceGone {
444-
it.t.Fatalf("Theia service did not disappear in time")
450+
it.t.Fatalf("Theia service:%s did not disappear in time", theiaName)
451+
return
452+
}
453+
// Wait for the theia endpoints to be properly deleted (i.e. syncing)
454+
var endpointGone bool
455+
for time.Since(start) < 1*time.Minute {
456+
_, err := k8s.CoreV1().Endpoints(ns).Get(ctx, theiaName, v1.GetOptions{})
457+
if errors.IsNotFound(err) {
458+
endpointGone = true
459+
break
460+
}
461+
time.Sleep(200 * time.Millisecond)
462+
}
463+
if !endpointGone {
464+
it.t.Fatalf("Theia endpoint:%s did not disappear in time", theiaName)
445465
return
446466
}
447467

test/tests/workspace/content_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ func TestBackup(t *testing.T) {
6565
return
6666
}
6767

68+
defer func() {
69+
t.Log("Cleaning up on TestBackup exit")
70+
sctx, scancel := context.WithTimeout(ctx, 5*time.Second)
71+
defer scancel()
72+
_, err = it.API().WorkspaceManager().StopWorkspace(sctx, &wsapi.StopWorkspaceRequest{
73+
Id: ws.Req.Id,
74+
})
75+
}()
76+
6877
var ls agent.ListDirResponse
6978
err = rsa.Call("WorkspaceAgent.ListDir", &agent.ListDirRequest{
7079
Dir: "/workspace",

0 commit comments

Comments
 (0)