enhance assertions in test/e2e/windows

Signed-off-by: hunknownz <klercc37@gmail.com>
This commit is contained in:
hunknownz 2022-05-31 18:20:26 +08:00
parent aae07c6f7b
commit fdb43cc5ad
3 changed files with 17 additions and 8 deletions

View File

@ -131,7 +131,9 @@ func runDensityBatchTest(f *framework.Framework, testArg densityTest) (time.Dura
for name, create := range createTimes { for name, create := range createTimes {
watch, ok := watchTimes[name] watch, ok := watchTimes[name]
framework.ExpectEqual(ok, true) if !ok {
framework.Failf("pod %s failed to be observed by the watch", name)
}
e2eLags = append(e2eLags, e2eLags = append(e2eLags,
e2emetrics.PodLatencyData{Name: name, Latency: watch.Time.Sub(create.Time)}) e2emetrics.PodLatencyData{Name: name, Latency: watch.Time.Sub(create.Time)})
@ -201,12 +203,16 @@ func newInformerWatchPod(f *framework.Framework, mutex *sync.Mutex, watchTimes m
cache.ResourceEventHandlerFuncs{ cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { AddFunc: func(obj interface{}) {
p, ok := obj.(*v1.Pod) p, ok := obj.(*v1.Pod)
framework.ExpectEqual(ok, true) if !ok {
framework.Failf("expected Pod, got %T", obj)
}
go checkPodRunning(p) go checkPodRunning(p)
}, },
UpdateFunc: func(oldObj, newObj interface{}) { UpdateFunc: func(oldObj, newObj interface{}) {
p, ok := newObj.(*v1.Pod) p, ok := newObj.(*v1.Pod)
framework.ExpectEqual(ok, true) if !ok {
framework.Failf("expected Pod, got %T", newObj)
}
go checkPodRunning(p) go checkPodRunning(p)
}, },
}, },

View File

@ -19,6 +19,7 @@ package windows
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/onsi/gomega"
"strings" "strings"
"time" "time"
@ -568,10 +569,10 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
// Note: This test performs relative comparisons to ensure metrics values were logged and does not validate specific values. // Note: This test performs relative comparisons to ensure metrics values were logged and does not validate specific values.
// This done so the test can be run in parallel with other tests which may start HostProcess containers on the same node. // This done so the test can be run in parallel with other tests which may start HostProcess containers on the same node.
ginkgo.By("Ensuring metrics were updated") ginkgo.By("Ensuring metrics were updated")
framework.ExpectEqual(beforeMetrics.StartedContainersCount < afterMetrics.StartedContainersCount, true, "Count of started HostProcess containers should increase") gomega.Expect(beforeMetrics.StartedContainersCount).To(gomega.BeNumerically("<", afterMetrics.StartedContainersCount), "Count of started HostProcess containers should increase")
framework.ExpectEqual(beforeMetrics.StartedContainersErrorCount < afterMetrics.StartedContainersErrorCount, true, "Count of started HostProcess errors containers should increase") gomega.Expect(beforeMetrics.StartedContainersErrorCount).To(gomega.BeNumerically("<", afterMetrics.StartedContainersErrorCount), "Count of started HostProcess errors containers should increase")
framework.ExpectEqual(beforeMetrics.StartedInitContainersCount < afterMetrics.StartedInitContainersCount, true, "Count of started HostProcess init containers should increase") gomega.Expect(beforeMetrics.StartedInitContainersCount).To(gomega.BeNumerically("<", afterMetrics.StartedInitContainersCount), "Count of started HostProcess init containers should increase")
framework.ExpectEqual(beforeMetrics.StartedInitContainersErrorCount < afterMetrics.StartedInitContainersErrorCount, true, "Count of started HostProcess errors init containers should increase") gomega.Expect(beforeMetrics.StartedInitContainersErrorCount).To(gomega.BeNumerically("<", afterMetrics.StartedInitContainersErrorCount), "Count of started HostProcess errors init containers should increase")
}) })
}) })

View File

@ -126,7 +126,9 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() {
framework.Logf("Using node: %v", targetNode.Name) framework.Logf("Using node: %v", targetNode.Name)
ginkgo.By("Getting bootid") ginkgo.By("Getting bootid")
framework.ExpectEqual(len(targetNode.Status.NodeInfo.BootID) != 0, true, "Should find bootId in kubelet stats") if len(targetNode.Status.NodeInfo.BootID) == 0 {
framework.Failf("expected bootId in kubelet stats, got none")
}
}) })
}) })