diff --git a/cmd/critest/cri_test.go b/cmd/critest/cri_test.go index 0822f09484..a25621ab30 100644 --- a/cmd/critest/cri_test.go +++ b/cmd/critest/cri_test.go @@ -23,14 +23,12 @@ import ( "math/rand" "os" "os/exec" - "path" "path/filepath" "strings" "testing" "time" "github.com/onsi/ginkgo/v2" - "github.com/onsi/ginkgo/v2/reporters" ginkgotypes "github.com/onsi/ginkgo/v2/types" "github.com/onsi/gomega" @@ -93,17 +91,7 @@ func isFlagSet(name string) bool { // runTestSuite runs cri validation tests and benchmark tests. func runTestSuite(t *testing.T) { gomega.RegisterFailHandler(ginkgo.Fail) - - reporter := []ginkgo.Reporter{} - if framework.TestContext.ReportDir != "" { - if err := os.MkdirAll(framework.TestContext.ReportDir, 0755); err != nil { - t.Errorf("Failed creating report directory: %v", err) - } - - reporter = append(reporter, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, fmt.Sprintf("junit_%v.xml", framework.TestContext.ReportPrefix)))) - } - - ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "CRI validation", reporter) + ginkgo.RunSpecs(t, "CRI validation") } func generateTempTestName() (string, error) { diff --git a/pkg/benchmark/benchmark.go b/pkg/benchmark/benchmark.go index a5e9feb68b..158ae7d7e2 100644 --- a/pkg/benchmark/benchmark.go +++ b/pkg/benchmark/benchmark.go @@ -17,26 +17,14 @@ limitations under the License. package benchmark import ( - "fmt" "math/rand" - "os" - "path" "testing" "time" - "github.com/golang/glog" - "github.com/kubernetes-sigs/cri-tools/pkg/framework" - "github.com/onsi/ginkgo/v2" - "github.com/onsi/ginkgo/v2/reporters" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -const ( - defaultOperationTimes int = 20 -) - // TestPerformance checks configuration parameters (specified through flags) and then runs // benchmark tests using the Ginkgo runner. // If a "report directory" is specified, one or more JUnit test reports will be @@ -44,19 +32,5 @@ const ( func TestPerformance(t *testing.T) { rand.Seed(time.Now().UTC().UnixNano()) RegisterFailHandler(Fail) - r := []Reporter{} - reportDir := framework.TestContext.ReportDir - if reportDir != "" { - // Create the directory if it doesn't already exists - if err := os.MkdirAll(reportDir, 0755); err != nil { - glog.Errorf("Failed creating report directory: %v", err) - } else { - suite, _ := ginkgo.GinkgoConfiguration() - // Configure a junit reporter to write to the directory - junitFile := fmt.Sprintf("junit_%s%02d.xml", framework.TestContext.ReportPrefix, suite.ParallelProcess) - junitPath := path.Join(reportDir, junitFile) - r = append(r, reporters.NewJUnitReporter(junitPath)) - } - } - RunSpecsWithDefaultAndCustomReporters(t, "Benchmark Test Suite", r) + RunSpecs(t, "Benchmark Test Suite") } diff --git a/pkg/benchmark/pod_container.go b/pkg/benchmark/pod_container.go index 07a3fa9d53..44e22fdb21 100644 --- a/pkg/benchmark/pod_container.go +++ b/pkg/benchmark/pod_container.go @@ -23,6 +23,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/onsi/gomega/gmeasure" ) const ( @@ -40,11 +41,17 @@ func getPodContainerBenchmarkTimeoutSeconds() int { var _ = framework.KubeDescribe("PodSandbox", func() { f := framework.NewDefaultCRIFramework() - var rc internalapi.RuntimeService - var ic internalapi.ImageManagerService - var podID string + var ( + experiment *gmeasure.Experiment + rc internalapi.RuntimeService + ic internalapi.ImageManagerService + podID string + ) BeforeEach(func() { + experiment = gmeasure.NewExperiment("start-container-benchmark") + AddReportEntry(experiment.Name, experiment) + rc = f.CRIClient.CRIRuntimeClient ic = f.CRIClient.CRIImageClient }) @@ -57,7 +64,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() { }) Context("benchmark about start a container from scratch", func() { - Measure("benchmark about start a container from scratch", func(b Benchmarker) { + It("benchmark about start a container from scratch", func() { var err error podSandboxName := "PodSandbox-for-creating-pod-and-container-performance-test-" + framework.NewUUID() @@ -69,7 +76,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() { Linux: &runtimeapi.LinuxPodSandboxConfig{}, } - operation := b.Time("create PodSandbox and container", func() { + operation := experiment.MeasureDuration("create PodSandbox and container", func() { By("run PodSandbox") podID, err = rc.RunPodSandbox(config, framework.TestContext.RuntimeHandler) framework.ExpectNoError(err, "failed to create PodSandbox: %v", err) @@ -81,6 +88,6 @@ var _ = framework.KubeDescribe("PodSandbox", func() { framework.ExpectNoError(err, "failed to start Container: %v", err) Expect(operation.Seconds()).Should(BeNumerically("<", getPodContainerBenchmarkTimeoutSeconds()), "create PodSandbox shouldn't take too long.") - }, defaultOperationTimes) + }) }) }) diff --git a/pkg/validate/e2e.go b/pkg/validate/e2e.go index 8507437109..643ae77860 100644 --- a/pkg/validate/e2e.go +++ b/pkg/validate/e2e.go @@ -17,18 +17,10 @@ limitations under the License. package validate import ( - "fmt" "math/rand" - "os" - "path" "testing" "time" - "github.com/golang/glog" - "github.com/kubernetes-sigs/cri-tools/pkg/framework" - "github.com/onsi/ginkgo/v2" - "github.com/onsi/ginkgo/v2/reporters" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -41,19 +33,5 @@ import ( func TestE2ECRI(t *testing.T) { rand.Seed(time.Now().UTC().UnixNano()) RegisterFailHandler(Fail) - r := []Reporter{} - reportDir := framework.TestContext.ReportDir - if reportDir != "" { - // Create the directory if it doesn't already exists - if err := os.MkdirAll(reportDir, 0755); err != nil { - glog.Errorf("Failed creating report directory: %v", err) - } else { - suite, _ := ginkgo.GinkgoConfiguration() - // Configure a junit reporter to write to the directory - junitFile := fmt.Sprintf("junit_%s%02d.xml", framework.TestContext.ReportPrefix, suite.ParallelProcess) - junitPath := path.Join(reportDir, junitFile) - r = append(r, reporters.NewJUnitReporter(junitPath)) - } - } - RunSpecsWithDefaultAndCustomReporters(t, "E2ECRI Suite", r) + RunSpecs(t, "E2ECRI Suite") }