mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Migrate ProgressReporter
to Ginkgo
V2
Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
parent
fd4b5b629b
commit
46a3954ba5
@ -74,9 +74,12 @@ const (
|
||||
namespaceCleanupTimeout = 15 * time.Minute
|
||||
)
|
||||
|
||||
var progressReporter = &e2ereporters.ProgressReporter{}
|
||||
|
||||
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
||||
// Reference common test to make the import valid.
|
||||
commontest.CurrentSuite = commontest.E2E
|
||||
progressReporter.SetStartMsg()
|
||||
setupSuite()
|
||||
return nil
|
||||
}, func(data []byte) {
|
||||
@ -85,6 +88,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
||||
})
|
||||
|
||||
var _ = ginkgo.SynchronizedAfterSuite(func() {
|
||||
progressReporter.SetEndMsg()
|
||||
CleanupSuite()
|
||||
}, func() {
|
||||
AfterSuiteActions()
|
||||
@ -98,7 +102,7 @@ var _ = ginkgo.SynchronizedAfterSuite(func() {
|
||||
func RunE2ETests(t *testing.T) {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
progressReporter = e2ereporters.NewProgressReporter(framework.TestContext.ProgressReportURL)
|
||||
gomega.RegisterFailHandler(framework.Fail)
|
||||
// Disable skipped tests unless they are explicitly requested.
|
||||
if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" {
|
||||
@ -117,9 +121,6 @@ func RunE2ETests(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Stream the progress to stdout and optionally a URL accepting progress updates.
|
||||
r = append(r, e2ereporters.NewProgressReporter(framework.TestContext.ProgressReportURL))
|
||||
|
||||
klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, config.GinkgoConfig.ParallelNode)
|
||||
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
|
||||
}
|
||||
|
@ -139,6 +139,10 @@ func TestE2E(t *testing.T) {
|
||||
RunE2ETests(t)
|
||||
}
|
||||
|
||||
var _ = ginkgo.ReportAfterEach(func(report ginkgo.SpecReport) {
|
||||
progressReporter.ProcessSpecReport(report)
|
||||
})
|
||||
|
||||
var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkgo.Report) {
|
||||
var err error
|
||||
// The DetailsRepoerter will output details about every test (name, files, lines, etc) which helps
|
||||
|
@ -25,19 +25,19 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/config"
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// ProgressReporter is a ginkgo reporter which tracks the total number of tests to be run/passed/failed/skipped.
|
||||
// As new tests are completed it updates the values and prints them to stdout and optionally, sends the updates
|
||||
// to the configured URL.
|
||||
// TODO: Number of test specs is not available now, we can add it back when this is fixed in the Ginkgo V2.
|
||||
// pls see: https://github.com/kubernetes/kubernetes/issues/109744
|
||||
type ProgressReporter struct {
|
||||
LastMsg string `json:"msg"`
|
||||
|
||||
TestsTotal int `json:"total"`
|
||||
TestsCompleted int `json:"completed"`
|
||||
TestsSkipped int `json:"skipped"`
|
||||
TestsFailed int `json:"failed"`
|
||||
@ -62,47 +62,8 @@ func NewProgressReporter(progressReportURL string) *ProgressReporter {
|
||||
return rep
|
||||
}
|
||||
|
||||
// SpecSuiteWillBegin is invoked by ginkgo when the suite is about to start and is the first point in which we can
|
||||
// antipate the number of tests which will be run.
|
||||
func (reporter *ProgressReporter) SpecSuiteWillBegin(cfg config.GinkgoConfigType, summary *types.SuiteSummary) {
|
||||
reporter.TestsTotal = summary.NumberOfSpecsThatWillBeRun
|
||||
reporter.LastMsg = "Test Suite starting"
|
||||
reporter.sendUpdates()
|
||||
}
|
||||
|
||||
// SpecSuiteDidEnd is the last method invoked by Ginkgo after all the specs are run.
|
||||
func (reporter *ProgressReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
|
||||
reporter.LastMsg = "Test Suite completed"
|
||||
reporter.sendUpdates()
|
||||
}
|
||||
|
||||
// SpecDidComplete is invoked by Ginkgo each time a spec is completed (including skipped specs).
|
||||
func (reporter *ProgressReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
||||
testname := strings.Join(specSummary.ComponentTexts[1:], " ")
|
||||
switch specSummary.State {
|
||||
case types.SpecStateFailed:
|
||||
if len(specSummary.ComponentTexts) > 0 {
|
||||
reporter.Failures = append(reporter.Failures, testname)
|
||||
} else {
|
||||
reporter.Failures = append(reporter.Failures, "Unknown test name")
|
||||
}
|
||||
reporter.TestsFailed++
|
||||
reporter.LastMsg = fmt.Sprintf("FAILED %v", testname)
|
||||
case types.SpecStatePassed:
|
||||
reporter.TestsCompleted++
|
||||
reporter.LastMsg = fmt.Sprintf("PASSED %v", testname)
|
||||
case types.SpecStateSkipped:
|
||||
reporter.TestsSkipped++
|
||||
return
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
reporter.sendUpdates()
|
||||
}
|
||||
|
||||
// sendUpdates serializes the current progress and prints it to stdout and also posts it to the configured endpoint if set.
|
||||
func (reporter *ProgressReporter) sendUpdates() {
|
||||
// SendUpdates serializes the current progress and prints it to stdout and also posts it to the configured endpoint if set.
|
||||
func (reporter *ProgressReporter) SendUpdates() {
|
||||
b := reporter.serialize()
|
||||
fmt.Println(string(b))
|
||||
go reporter.postProgressToURL(b)
|
||||
@ -143,11 +104,40 @@ func (reporter *ProgressReporter) serialize() []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// SpecWillRun is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *ProgressReporter) SpecWillRun(specSummary *types.SpecSummary) {}
|
||||
func (reporter *ProgressReporter) SetStartMsg() {
|
||||
reporter.LastMsg = "Test Suite starting"
|
||||
reporter.SendUpdates()
|
||||
}
|
||||
|
||||
// BeforeSuiteDidRun is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *ProgressReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {}
|
||||
// ProcessSpecReport summarizes the report state and sends the state to the configured endpoint if set.
|
||||
func (reporter *ProgressReporter) ProcessSpecReport(report ginkgo.SpecReport) {
|
||||
testName := strings.Join(report.ContainerHierarchyTexts, " ")
|
||||
if len(report.LeafNodeText) > 0 {
|
||||
testName = testName + " " + report.LeafNodeText
|
||||
}
|
||||
switch report.State {
|
||||
case types.SpecStateFailed:
|
||||
if len(testName) > 0 {
|
||||
reporter.Failures = append(reporter.Failures, testName)
|
||||
} else {
|
||||
reporter.Failures = append(reporter.Failures, "Unknown test name")
|
||||
}
|
||||
reporter.TestsFailed++
|
||||
reporter.LastMsg = fmt.Sprintf("FAILED %v", testName)
|
||||
case types.SpecStatePassed:
|
||||
reporter.TestsCompleted++
|
||||
reporter.LastMsg = fmt.Sprintf("PASSED %v", testName)
|
||||
case types.SpecStateSkipped:
|
||||
reporter.TestsSkipped++
|
||||
return
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
// AfterSuiteDidRun is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *ProgressReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {}
|
||||
reporter.SendUpdates()
|
||||
}
|
||||
|
||||
func (reporter *ProgressReporter) SetEndMsg() {
|
||||
reporter.LastMsg = "Test Suite completed"
|
||||
reporter.SendUpdates()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user