8
8
"context"
9
9
"fmt"
10
10
"io"
11
+ "strings"
11
12
"sync"
12
13
"time"
13
14
@@ -413,13 +414,14 @@ func (it *Test) WaitForWorkspaceStop(instanceID string) (lastStatus *wsmanapi.Wo
413
414
if desc != nil {
414
415
switch desc .Status .Phase {
415
416
case wsmanapi .WorkspacePhase_STOPPED :
416
- return desc .Status
417
+ // ensure theia service is cleaned up
418
+ lastStatus = desc .Status
417
419
}
418
420
}
419
421
420
422
select {
421
423
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 ())
423
425
return
424
426
case <- done :
425
427
}
@@ -432,16 +434,34 @@ func (it *Test) WaitForWorkspaceStop(instanceID string) (lastStatus *wsmanapi.Wo
432
434
serviceGone bool
433
435
k8s , ns = it .API ().Kubernetes ()
434
436
)
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 )))
435
441
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 {})
437
443
if errors .IsNotFound (err ) {
438
444
serviceGone = true
439
445
break
440
446
}
441
447
time .Sleep (200 * time .Millisecond )
442
448
}
443
449
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 )
445
465
return
446
466
}
447
467
0 commit comments