Skip to content

Commit b1b8707

Browse files
authored
Fix smoke_test (#870)
1 parent e2c2c15 commit b1b8707

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

test/e2e/smoke_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
variantautoscalingv1alpha1 "github.com/llm-d/llm-d-workload-variant-autoscaler/api/v1alpha1"
1919
"github.com/llm-d/llm-d-workload-variant-autoscaler/internal/constants"
2020
"github.com/llm-d/llm-d-workload-variant-autoscaler/test/e2e/fixtures"
21+
"github.com/llm-d/llm-d-workload-variant-autoscaler/test/utils"
2122
)
2223

2324
var _ = Describe("Smoke Tests - Infrastructure Readiness", Label("smoke", "full"), func() {
@@ -120,6 +121,16 @@ var _ = Describe("Smoke Tests - Infrastructure Readiness", Label("smoke", "full"
120121
// Note: InferencePool should already exist from infra-only deployment
121122
// We no longer create InferencePools in individual tests
122123

124+
By("Deleting all existing VariantAutoscaling objects for clean test state")
125+
deletedCount, vaCleanupErr := utils.DeleteAllVariantAutoscalings(ctx, crClient, cfg.LLMDNamespace)
126+
if vaCleanupErr != nil {
127+
GinkgoWriter.Printf("Warning: Failed to clean up existing VAs: %v\n", vaCleanupErr)
128+
} else if deletedCount > 0 {
129+
GinkgoWriter.Printf("Deleted %d existing VariantAutoscaling objects\n", deletedCount)
130+
} else {
131+
GinkgoWriter.Println("No existing VariantAutoscaling objects found")
132+
}
133+
123134
By("Creating model service deployment")
124135
err := fixtures.EnsureModelService(ctx, k8sClient, cfg.LLMDNamespace, modelServiceName, poolName, cfg.ModelID, cfg.UseSimulator, cfg.MaxNumSeqs)
125136
Expect(err).NotTo(HaveOccurred(), "Failed to create model service")

test/utils/e2eutils.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
autoscalingv2 "k8s.io/api/autoscaling/v2"
4646
batchv1 "k8s.io/api/batch/v1"
4747
corev1 "k8s.io/api/core/v1"
48+
"k8s.io/apimachinery/pkg/api/errors"
4849
"k8s.io/apimachinery/pkg/api/resource"
4950
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5051
"k8s.io/apimachinery/pkg/util/wait"
@@ -1247,3 +1248,47 @@ func SetupTestEnvironment(image string, numNodes, gpusPerNode int, gpuTypes stri
12471248
gom.Expect(os.Setenv("DEPLOY_HPA", "false")).To(gom.Succeed()) // tests create their own HPAs if needed
12481249
gom.Expect(os.Setenv("VLLM_SVC_ENABLED", "false")).To(gom.Succeed()) // tests deploy their own Service
12491250
}
1251+
1252+
// DeleteAllVariantAutoscalings deletes all VariantAutoscaling objects in a namespace
1253+
// and waits for them to be fully removed. This is useful for ensuring a clean test state.
1254+
// Returns the number of VAs that were deleted.
1255+
func DeleteAllVariantAutoscalings(ctx context.Context, crClient client.Client, namespace string) (int, error) {
1256+
vaList := &v1alpha1.VariantAutoscalingList{}
1257+
if err := crClient.List(ctx, vaList, client.InNamespace(namespace)); err != nil {
1258+
return 0, fmt.Errorf("failed to list VariantAutoscaling objects: %w", err)
1259+
}
1260+
1261+
if len(vaList.Items) == 0 {
1262+
return 0, nil
1263+
}
1264+
1265+
deletedCount := 0
1266+
for i := range vaList.Items {
1267+
va := &vaList.Items[i]
1268+
if err := crClient.Delete(ctx, va); err != nil {
1269+
if errors.IsNotFound(err) {
1270+
continue // Already deleted
1271+
}
1272+
return deletedCount, fmt.Errorf("failed to delete VA %s: %w", va.Name, err)
1273+
}
1274+
deletedCount++
1275+
}
1276+
1277+
// Wait for all VAs to be fully deleted (with timeout)
1278+
waitCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
1279+
defer cancel()
1280+
1281+
err := wait.PollUntilContextTimeout(waitCtx, 2*time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) {
1282+
remainingVAs := &v1alpha1.VariantAutoscalingList{}
1283+
if err := crClient.List(ctx, remainingVAs, client.InNamespace(namespace)); err != nil {
1284+
return false, err
1285+
}
1286+
return len(remainingVAs.Items) == 0, nil
1287+
})
1288+
1289+
if err != nil {
1290+
return deletedCount, fmt.Errorf("timeout waiting for VAs to be deleted: %w", err)
1291+
}
1292+
1293+
return deletedCount, nil
1294+
}

0 commit comments

Comments
 (0)