Skip to content

Commit 617c094

Browse files
committed
Add an e2e test
Signed-off-by: Itamar Holder <[email protected]>
1 parent 54500bf commit 617c094

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

test/e2e_node/swap_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333

3434
"github.com/onsi/ginkgo/v2"
3535
"github.com/onsi/gomega"
36+
"github.com/onsi/gomega/gstruct"
3637
v1 "k8s.io/api/core/v1"
3738
"k8s.io/apimachinery/pkg/api/resource"
3839
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -56,7 +57,7 @@ var (
5657
noLimits *resource.Quantity = nil
5758
)
5859

59-
var _ = SIGDescribe("Swap", "[LinuxOnly]", feature.Swap, framework.WithSerial(), func() {
60+
var _ = SIGDescribe("Swap", "[LinuxOnly]", ginkgo.Ordered, feature.Swap, framework.WithSerial(), func() {
6061
f := framework.NewDefaultFramework("swap-qos")
6162
addAfterEachForCleaningUpPods(f)
6263
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
@@ -287,6 +288,69 @@ var _ = SIGDescribe("Swap", "[LinuxOnly]", feature.Swap, framework.WithSerial(),
287288
err := podClient.Delete(context.Background(), stressPod.Name, metav1.DeleteOptions{})
288289
framework.ExpectNoError(err)
289290
})
291+
292+
ginkgo.It("ensure summary API properly reports swap", func() {
293+
stressSize := divideQuantity(nodeTotalMemory, 5)
294+
ginkgo.By("Creating a stress pod with stress size: " + stressSize.String())
295+
stressPod := getStressPod(stressSize)
296+
297+
memoryLimit := cloneQuantity(stressSize)
298+
memoryLimit.Sub(resource.MustParse("50Mi"))
299+
memoryRequest := divideQuantity(memoryLimit, 2)
300+
ginkgo.By("Adding memory request of " + memoryRequest.String() + " and memory limit of " + memoryLimit.String())
301+
setPodMemoryResources(stressPod, memoryRequest, memoryLimit)
302+
gomega.Expect(qos.GetPodQOS(stressPod)).To(gomega.Equal(v1.PodQOSBurstable))
303+
304+
stressPod = runPodAndWaitUntilScheduled(f, stressPod)
305+
306+
ginkgo.By("Ensuring the pod is using swap")
307+
var swapUsage *resource.Quantity
308+
gomega.Eventually(func() error {
309+
stressPod = getUpdatedPod(f, stressPod)
310+
gomega.Expect(stressPod.Status.Phase).To(gomega.Equal(v1.PodRunning), "pod should be running")
311+
312+
var err error
313+
swapUsage, err = getSwapUsage(f, stressPod)
314+
if err != nil {
315+
return err
316+
}
317+
318+
if swapUsage.IsZero() {
319+
return fmt.Errorf("swap usage is zero")
320+
}
321+
322+
return nil
323+
}, 5*time.Minute, 1*time.Second).Should(gomega.Succeed())
324+
325+
ginkgo.By("Waiting 15 seconds for cAdvisor to collect 2 stats points")
326+
time.Sleep(15 * time.Second)
327+
328+
getSwapExpectation := func() gomega.OmegaMatcher {
329+
return gstruct.PointTo(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
330+
"Time": recent(maxStatsAge),
331+
"SwapUsageBytes": bounded(1, memoryLimit.Value()),
332+
}))
333+
}
334+
335+
matchExpectations := gstruct.PointTo(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
336+
"Pods": gstruct.MatchElements(summaryObjectID, gstruct.IgnoreExtras, gstruct.Elements{
337+
fmt.Sprintf("%s::%s", f.Namespace.Name, stressPod.Name): gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
338+
"Containers": gstruct.MatchElements(summaryObjectID, gstruct.IgnoreExtras, gstruct.Elements{
339+
stressPod.Spec.Containers[0].Name: gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
340+
"Swap": getSwapExpectation(),
341+
}),
342+
}),
343+
"Swap": getSwapExpectation(),
344+
}),
345+
}),
346+
}))
347+
348+
ginkgo.By("Validating /stats/summary")
349+
// Give pods a minute to actually start up.
350+
gomega.Eventually(context.Background(), getNodeSummary, 180*time.Second, 15*time.Second).Should(matchExpectations)
351+
// Then the summary should match the expectations a few more times.
352+
gomega.Consistently(context.Background(), getNodeSummary, 30*time.Second, 15*time.Second).Should(matchExpectations)
353+
})
290354
})
291355
})
292356
})

0 commit comments

Comments
 (0)