Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to native ginkgo v2 #938

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions cmd/critest/cri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 1 addition & 27 deletions pkg/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,20 @@ 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
// generated in this directory.
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")
}
46 changes: 28 additions & 18 deletions pkg/benchmark/pod_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gmeasure"
)

const (
Expand All @@ -40,26 +41,22 @@ 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
)

BeforeEach(func() {
experiment = gmeasure.NewExperiment("start-container-benchmark")
AddReportEntry(experiment.Name, experiment)

rc = f.CRIClient.CRIRuntimeClient
ic = f.CRIClient.CRIImageClient
})

AfterEach(func() {
By("stop PodSandbox")
rc.StopPodSandbox(podID)
By("delete PodSandbox")
rc.RemovePodSandbox(podID)
})

Context("benchmark about start a container from scratch", func() {
Measure("benchmark about start a container from scratch", func(b Benchmarker) {
var err error

It("benchmark about start a container from scratch", func() {
podSandboxName := "PodSandbox-for-creating-pod-and-container-performance-test-" + framework.NewUUID()
uid := framework.DefaultUIDPrefix + framework.NewUUID()
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()
Expand All @@ -69,18 +66,31 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
Linux: &runtimeapi.LinuxPodSandboxConfig{},
}

operation := b.Time("create PodSandbox and container", func() {
benchmark := func() {
By("run PodSandbox")
podID, err = rc.RunPodSandbox(config, framework.TestContext.RuntimeHandler)
podID, err := rc.RunPodSandbox(config, framework.TestContext.RuntimeHandler)
framework.ExpectNoError(err, "failed to create PodSandbox: %v", err)

By("create container in PodSandbox")
containerID := framework.CreateDefaultContainer(rc, ic, podID, config, "Pod-Container-for-creating-benchmark-")

By("start container in PodSandbox")
err = rc.StartContainer(containerID)
})
framework.ExpectNoError(err, "failed to start Container: %v", err)

By("stop PodSandbox")
rc.StopPodSandbox(podID)
By("delete PodSandbox")
rc.RemovePodSandbox(podID)
}

// Run a single test to ensure images are available and everything works
benchmark()

// Do the benchmark
saschagrunert marked this conversation as resolved.
Show resolved Hide resolved
operation := experiment.MeasureDuration("create PodSandbox and container", benchmark)

framework.ExpectNoError(err, "failed to start Container: %v", err)
Expect(operation.Seconds()).Should(BeNumerically("<", getPodContainerBenchmarkTimeoutSeconds()), "create PodSandbox shouldn't take too long.")
}, defaultOperationTimes)
})
})
})
24 changes: 1 addition & 23 deletions pkg/validate/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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")
}