Skip to content

Commit c37f95c

Browse files
committed
test(e2e): fix debug mode test timing and add PVC cleanup
Signed-off-by: Oleksii Kurinnyi <[email protected]>
1 parent 948666e commit c37f95c

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

test/e2e/pkg/client/devws.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import (
2626

2727
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
2828
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/apimachinery/pkg/util/wait"
3032
)
3133

3234
func (w *K8sClient) UpdateDevWorkspaceStarted(name, namespace string, started bool) error {
@@ -105,3 +107,35 @@ func (w *K8sClient) DeleteDevWorkspace(name, namespace string) error {
105107
}
106108
return nil
107109
}
110+
111+
// WaitForPVCDeleted waits for a PVC to be fully deleted from the cluster.
112+
// Returns true if deleted successfully, false if timeout occurred.
113+
func (w *K8sClient) WaitForPVCDeleted(pvcName, namespace string, timeout time.Duration) (bool, error) {
114+
deleted := false
115+
err := wait.PollImmediate(2*time.Second, timeout, func() (bool, error) {
116+
_, err := w.Kube().CoreV1().PersistentVolumeClaims(namespace).
117+
Get(context.TODO(), pvcName, metav1.GetOptions{})
118+
119+
if k8sErrors.IsNotFound(err) {
120+
deleted = true
121+
return true, nil
122+
}
123+
if err != nil {
124+
return false, err
125+
}
126+
return false, nil
127+
})
128+
return deleted, err
129+
}
130+
131+
// DeleteDevWorkspaceAndWait deletes a workspace and waits for its PVC to be fully removed.
132+
// This ensures proper cleanup and prevents PVC conflicts in subsequent tests.
133+
func (w *K8sClient) DeleteDevWorkspaceAndWait(name, namespace string) error {
134+
if err := w.DeleteDevWorkspace(name, namespace); err != nil {
135+
return err
136+
}
137+
138+
// Wait for shared PVC to be deleted (may take time in cloud environments)
139+
_, err := w.WaitForPVCDeleted("claim-devworkspace", namespace, 2*time.Minute)
140+
return err
141+
}

test/e2e/pkg/tests/devworkspace_debug_poststart_tests.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import (
2525
var _ = ginkgo.Describe("[DevWorkspace Debug Start Mode]", func() {
2626
defer ginkgo.GinkgoRecover()
2727

28+
const workspaceName = "code-latest-with-debug-start"
29+
30+
ginkgo.AfterEach(func() {
31+
// Clean up workspace and wait for PVC to be fully deleted
32+
// This prevents PVC conflicts in subsequent tests, especially in CI environments
33+
_ = config.DevK8sClient.DeleteDevWorkspaceAndWait(workspaceName, config.DevWorkspaceNamespace)
34+
})
35+
2836
ginkgo.It("Wait DevWorkspace Webhook Server Pod", func() {
2937
controllerLabel := "app.kubernetes.io/name=devworkspace-webhook-server"
3038

@@ -39,21 +47,21 @@ var _ = ginkgo.Describe("[DevWorkspace Debug Start Mode]", func() {
3947
}
4048
})
4149

42-
ginkgo.It("Add Debug DevWorkspace to cluster and wait starting status", func() {
50+
ginkgo.It("Add Debug DevWorkspace to cluster and wait running status", func() {
4351
commandResult, err := config.DevK8sClient.OcApplyWorkspace(config.DevWorkspaceNamespace, "test/resources/simple-devworkspace-debug-start-annotation.yaml")
4452
if err != nil {
4553
ginkgo.Fail(fmt.Sprintf("Failed to create DevWorkspace: %s %s", err.Error(), commandResult))
4654
return
4755
}
4856

49-
deploy, err := config.DevK8sClient.WaitDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace, dw.DevWorkspaceStatusStarting)
57+
deploy, err := config.DevK8sClient.WaitDevWsStatus(workspaceName, config.DevWorkspaceNamespace, dw.DevWorkspaceStatusRunning)
5058
if !deploy {
5159
ginkgo.Fail(fmt.Sprintf("DevWorkspace didn't start properly. Error: %s", err))
5260
}
5361
})
5462

5563
ginkgo.It("Check DevWorkspace Conditions for Debug Start message", func() {
56-
devWorkspaceStatus, err := config.DevK8sClient.GetDevWsStatus("code-latest-with-debug-start", config.DevWorkspaceNamespace)
64+
devWorkspaceStatus, err := config.DevK8sClient.GetDevWsStatus(workspaceName, config.DevWorkspaceNamespace)
5765
if err != nil {
5866
ginkgo.Fail(fmt.Sprintf("Failure in fetching DevWorkspace status. Error: %s", err))
5967
}

0 commit comments

Comments
 (0)