Skip to content

Commit

Permalink
Migrate to native ginkgo v2
Browse files Browse the repository at this point in the history
Two migrations needs to be done to avoid the following warnings:

```
You're using deprecated Ginkgo functionality:
=============================================
  Support for custom reporters has been removed in V2.  Please read the documentation linked to below for Ginkgo's new behavior and for a migration path:
  Learn more at: https://onsi.github.io/ginkgo/MIGRATING_TO_V2#removed-custom-reporters
  Measure is deprecated and will be removed in Ginkgo V2.  Please migrate to gomega/gmeasure.
  Learn more at: https://onsi.github.io/ginkgo/MIGRATING_TO_V2#removed-measure
    github.com/kubernetes-sigs/cri-tools/pkg/benchmark/pod_container.go:60
```

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed May 24, 2022
1 parent 55e46f5 commit 876ba45
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 69 deletions.
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")
}
19 changes: 13 additions & 6 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,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
})
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
})
})
})
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")
}

0 comments on commit 876ba45

Please sign in to comment.